Hello...
I have a c++ project and want to use this in a c# program. So, I
thought I could make a dll from this c++ code. But I didn't find the
right solution at this moment. Maybe you can help me The c++ program
consists of about 15 files (.cpp and .h). I think I have to remove the
main method, but then ... In my c# programm, I want to call some
functions of the c++ code...
Regards,
Jacquipre.

Create an dll from existing c++ project
Direct9.0SDK Itanium Version
Harish
So, are you still getting the IO exception
Chi Lap
x.dll is a native VC++ dll of a third party (with code). I have to use this in my C# application. It has got a lot of classes and each are having large number of functions. So created a VC .net class library (xdnet.dll). First compiled x.dll in \clr and referenced in xdnet.dll. For test reasons, I wrapped one of the classes of the x.dll in this fashion:
Peter_H
See http://msdn2.microsoft.com/en-us/library/ms235281(VS.80).aspx
.netguy
You should look at using C++ interop instead of P/Invoke. It's far more convenient to use.
And your error seems to indicate that the P/Invoke layer could not find such a function in the DLL. Possibly it's name mangled.
ianRm
When you write a mixed-mode wrapper, you are still using C++ Interop there. I guess your question is whether a wrapper DLL needs to be there, when you can directly use the original DLL, (converting it to a /clr DLL) since you have its source code.
I'd probably do the wrapper DLL - that way the original DLL is kept native, and fast, and native callers can call directly into it.
JLee
From C#, using P/Invoke, you can only access exported functions in native DLLs. You cannot access exported C++ classes using that technique.
If you insist on using P/Invoke, you'd have to write wrapper functions for every class method (or sequence of methods).
For e.g., if you have a class A with methods int F1() and void F2(char*), you could do something like this :-
int AF1()
{
A a;
return a.F1();
}
and
void AF2(char* p)
{
A a;
a.F2(p);
}
Now export AF1 and AF2 and P/Invoke them from C#.
Again, this technique won't be very convenient for classes that have state (like a class that opens a file or a network stream and have methods that access the opened file or stream)
Anatoly Ponomarev - MSFT
Well, if the c++ code is completely native then there are two ways of doing this. But the very first thing you need to do is to create a native DLL and export all the functions you wish to export. Under VS 2005 this is done by creating a win32 project and selecting DLL. You then enter all the code files you wish and there you go.
Once you have the native DLL then you are ready to try and get the native functions exported. The ways of doing this are by either a managed DLL written in c++ which wraps the native functions, i.e. the managed functions just basically call the native functions. Or by using platform invoke under c#. There is pleanty of information on platform invoke in the msdn but I think the tricky part would be doing the managed wrapper.
From my understanding, there is no real difference in performance between the two so the choice of what you do is up to you.
If on the other hand it is a managed project, you have it easier, you just need to create a managed assembly and import that into the c# project.
MisterChief117
f.ex:
__declspec(dllexport) double** GetMfccData(int);
How do I write a managed wrapper
How can I now use this in my c# program exactly Can you give me an example
xulei
In an effort to upgrade my old VC++ project to C#, I had to wrap a third party VC dll containg lots of classes and functions.
Per Nish's say in this context, I have created a mixed-wrapper class, "ManagedDLL". Via a pointer, all the native C/C++ functions are being referred. The wrapped class was successfully referenced in the C# application. There are no compilation errors, but at runtime, I get:
Additional information: File or assembly name Managed DLL, or one of its dependencies, was not found."
I am not able to instantiate the dll constructor....
This is a problem that is boggling me for a long time now and all my development time is running out!
Suggestions/Tips please........
Thanks in advance,
Harish.
Jim M.
I didn't get it.
Maybe, I try to explain: I have some native c++ classes in one project. I compile this project as a .dll. This works, I think. If I now want to write a managed wrapper for some methods, how will I do this
Must I made a new project (in visual studio) and include the unmanaged .dll to wrap it Then I made a second (managed) .dll Is that right
Sorry... :-)
bumz
hhhmm..... Yes, the original dll has to be in the same folder as the wrapper class.
By the way, the code of the original dll is available. Just for confirmation, in these situations, do you feel that C++ Interops (Implicit PInvoke) would be a better choice over wrapper classes Even otherwise, I could create the wrapper class quiet easily with a little project-setting changes for a mixed dll.
Andy Engle
The original DLL needs to be in the same folder as the wrapper DLL. Is that the case here
Riaan
Thanks for your help!
ank1974
My method in the c++ native code looks like this:
__declspec(dllexport) void extractAll();
In my c# code, I wrote:
private void button1_Click(object sender, System.EventArgs e)
{
extractAll();
}
[DllImport("Extract_Mfcc.dll")]
public static extern void extractAll();
But now I get an error:
'System.EntryPointNotFoundException'
What is wrong