Hello! I am really clued how to import a code written in C (with its own functions) to C# windows form project. My idea is to to pass arguments to the functions in the C.dll from C# code. For example i have some buttons and when they are triggered i want to pass some arguments (array and others) to a sorting function in the C.dll.
I was googling and found Using C DLLs in C# (Visual Studio 2008) but when i tried to execute the code to see how it works i got the message add doesnt exist in the current context. ( using Visual Studio 2010)I
i am still novice and learning C,C++ and C# and i know that what i am trying to achieve is stupid, but i want to be able to run C code with windows forms.
Thanks in advance!
17 replies to this topic
#1
Posted 26 January 2012 - 04:48 AM
|
|
|
#2
Posted 26 January 2012 - 09:07 AM
Have you added the DLL as a reference to the project? I'm guessing that the dll was not moved into the bin directory of your C# application. Open the bin directory to make sure it is there. If not, copy it over.
#3
Posted 26 January 2012 - 09:44 AM
I have it there and got the same error. :X
#4
Posted 26 January 2012 - 09:52 AM
Are you using .NET 4? If so,
[DllImport("YourDll.dll", CallingConvention = CallingConvention.Cdecl)]
[DllImport("YourDll.dll", CallingConvention = CallingConvention.Cdecl)]
#5
Posted 26 January 2012 - 10:07 AM
Tried still not compiling ... Have the using System.Runtime.InteropServices; and copied the program from the site.. Interesting/
#6
Posted 26 January 2012 - 10:12 AM
Wait. It's not compiling? Did you compile the dll first, then copy it into the C# project's bin?
Can you post your code?
Can you post your code?
#7
Posted 26 January 2012 - 10:16 AM
Build the project(dll one) with the _declspec(dllexport) and stuff-> went to his release folder copied the DLL and paste in C# bin folder. And the C# project cant be run/compiled
#8
Posted 26 January 2012 - 10:34 AM
I'm sorry if this sounds stupid, but by default, VS starts with DEBUG as the default build. Is that set to release?
#9
Posted 26 January 2012 - 10:47 AM
" OK, now after you build the project, you'll have a testdll.dll file in the project folder. This is the DLL file that we'll be copying to the C# Project folder. "
Build-> Build solution (creates the dll in the release folder)
Build-> Build solution (creates the dll in the release folder)
#10
Posted 26 January 2012 - 11:06 AM
yes, copy everything from the c++ bin directory into the C# project's bin directory (under debug or release)
#11
Posted 26 January 2012 - 12:23 PM
Thanks for the help lespauled !!! Pulled it off at last. OK first step done so i need to know how to manipulate forms - set background image- logo. And again ty vm.
#12
Posted 26 January 2012 - 12:28 PM
Anytime.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









