-
December 16th, 2019, 08:54 PM
#1
Calling Visual Studio DLL in a C# program
Dear All,
I am doing a project in two diffents environments: The calling fuction in C# and the DLLs in Visual Studio C++, as I feel a "little comfortable" in VS C ++.
Unfortunately, although this is clearly visible in the project, we cannot add it as a reference in the C# project.
How could we manage that ?
Thank you for help.
Ambroise YAO
-
December 18th, 2019, 01:56 PM
#2
Re: Calling Visual Studio DLL in a C# program
Hi There,
As regard to my problem, I try to resolve it in 3 phases:
1. make a DLL + LIB in VS C (ex. CalculationAverage function)
2. make a class in C ++ to call this DLL (+ LIB)
3. call this C ++ class in C #
The first is OK.
But the 2nd point is not OK, because I cannot access the functions defined in 1). The error is that the function is unknown, despite everything I give it (.LIB, .H)
Can someone help me take this step?
Best Regards
Ambroise YAO
-
December 18th, 2019, 03:05 PM
#3
Re: Calling Visual Studio DLL in a C# program
C# via pinvoke can only call DLLs having functions exported with c-style signatures.
So this means that you cannot call a DLL from C# that exports C++ classes.
This is because there is no standard around the c++ name mangling so it is compiler and version specific and as a result, the pinvoke approach in .net won't work.
That being said, you can implement the DLL internally with C++ as long as the exported functions are c-style and don't pass classes.
For help with looking a pinvoke examples, see http://pinvoke.net
Last edited by Arjay; December 20th, 2019 at 11:44 AM.
-
December 20th, 2019, 11:30 AM
#4
Re: Calling Visual Studio DLL in a C# program
Hi,
I was facing the same situation and I fixed it by doing as recommaded by the post of ARJAY
James
-
December 20th, 2019, 11:30 AM
#5
Re: Calling Visual Studio DLL in a C# program
OK, thank you.
It is working
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|