C# app using a C++ dll
-
I have a C++ dll. I would like to use a C# to access two methods within that dll. What is the best way to do this. I cannot seem to find much information on getting the C# app to talk to the C++ dll. Is this possible? If so, how? Thanks, cw
#region signature my articles #endregion
-
#region signature my articles #endregion
I tried placing [DllImport("My.dll")] static extern int MakeQUERY(string strTag) ; Inside my C# class. The call MakeQUERY is in my C++ dll. But when i try to build this, i get an error: "The type or namespace name "DllImport" could not be found(are you missing a using directive or an assembly reference)
-
I tried placing [DllImport("My.dll")] static extern int MakeQUERY(string strTag) ; Inside my C# class. The call MakeQUERY is in my C++ dll. But when i try to build this, i get an error: "The type or namespace name "DllImport" could not be found(are you missing a using directive or an assembly reference)
Yeah, that happens a lot. It typically means you are missing a using directive or an assembly reference (and probably both). Have a look at some other program that tries to do what you are trying, i.e. search CodeProject (or Google) for "DllImport" :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google
-
I tried placing [DllImport("My.dll")] static extern int MakeQUERY(string strTag) ; Inside my C# class. The call MakeQUERY is in my C++ dll. But when i try to build this, i get an error: "The type or namespace name "DllImport" could not be found(are you missing a using directive or an assembly reference)
You will need to add this one line to able to use DllImport. using System.Runtime.InteropServices; Cheers.
------------------------------------------------------------------ Life would have been much easier if I had the source-code!!
-
You will need to add this one line to able to use DllImport. using System.Runtime.InteropServices; Cheers.
------------------------------------------------------------------ Life would have been much easier if I had the source-code!!
Thanks that got me further. Now it is throwing a System.EntryPointNotFound error. My dll looks like this. #include "stdafx.h" #include "Mydll.h" #include #include #include BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } DLL_API MakeQUERY(LPCSTR strTH, LPCSTR strEH, LPCSTR strSenderID, std::string strPath) { } I added this to my C# declaration [DllImport("LCIBroker.dll", EntryPoint = "DllMain")] But it still cannot find the EntryPoint. Is there something that i am missing?