0

Possible Duplicate:
Have to use C# dll to call C++ dll?

This is my first program related to importing external dll to my C# code. I created a DLl (Win 32 Dynamic Link Library) from visual C++ code. Let me paste the content of .cpp and .h file:

#include...
#
using namespace std;
BOOL APIENTRY DllMain( HANDLE hModule,DWORD  ul_reason_for_call, LPVOID lpReserved)
{   
      return TRUE;
}

unsigned char* decrypt(string stringKSN, string key){ #### some code
     convert(key_new);
return key_new
}

void convert(char * a) { ## return "some_value"
}

I build the visual c++ project and it created a finalDLL.dll.Now i want to use this dll into my c# code. I searched it on google and found that we can import the dll in c# project with the help of p/invoke exports. But when i compare the sample code with the above one it was totally different.

I am not able to test whether finalDLL.dll is corrected or corrupted?

Please help me to complete my import task.

Community
  • 1
  • 1
Amit Pal
  • 10,604
  • 26
  • 80
  • 160
  • can't you simply add a reference to your DLL in C# project? – CapelliC Dec 20 '12 at 10:17
  • It shows me following error: A reference to the "....dll" could not be added.Please make sure that the file is accessible and that it is a valid assembly or COM component. – Amit Pal Dec 20 '12 at 10:18
  • what about adding a reference to *project* that built the DLL ? – CapelliC Dec 20 '12 at 10:19
  • @CapelliC didn't got your above comment – Amit Pal Dec 20 '12 at 10:21
  • Look at this Thread: http://stackoverflow.com/questions/5193243/importing-c-dll-in-c-sharp-project – Link Dec 20 '12 at 10:23
  • when you select 'add reference' you can choice the type of the 'object' to reference. I used (when I had MSVS) a workspace with multiple projects inside, usually some DLL and then the application code that used them – CapelliC Dec 20 '12 at 10:23
  • Oh i forgot to tell you that i have created a Win32 Dynamic-Link Library – Amit Pal Dec 20 '12 at 10:24
  • @CapelliC Will it create a effect on importing? – Amit Pal Dec 20 '12 at 10:27
  • you are better of to forget about P/Invoke all together, and instead either write your decrupt function completely in C++/CLI or else make a seperate C++/CLI dll that calls your original dll – stijn Dec 20 '12 at 10:27
  • possible duplicate of [Have to use C# dll to call C++ dll?](http://stackoverflow.com/questions/3073303/have-to-use-c-sharp-dll-to-call-c-dll) and also http://stackoverflow.com/questions/3574208/how-do-i-use-the-c-dll-in-c-sharp and http://stackoverflow.com/questions/2995513/using-c-dll-in-c-sharp-project – stijn Dec 20 '12 at 10:29
  • @stijn Please check my question. I am not creating the c# dll – Amit Pal Dec 20 '12 at 10:30
  • sorry but that doesn't matter, this topic has been asked and answered in all it's forms here, just search for `c++ c# dll` for example. The answers are always the same... either you use P/Invoke and make sure to use correct calling conventions etc (hence no std::string arguments), or you make a CLI layer in between. – stijn Dec 20 '12 at 10:33

0 Answers0