skip to Main Content

Description-:

I am trying to implement Marshaling, trying to use C++ libraries in C# code in Visual Studio.

I have a C++ project that runs perfectly fine when build in Win32 solution platform, but when build in x64 solution platform throws error-:
enter image description here

And i have C# program that runs on x64, x86 or AnyCPU platform.

And if i try to build C++ project in Win32 platform and use the dll’s created into x64,x86 or AnyCPU platform of my c# application.It shows error-:

enter image description here

Requirement-:

How can i use .dll files generated by my c++ project into my c# application.

2

Answers


  1. Chosen as BEST ANSWER
    1. The first error was because of the different Runtime Library in Project->Properties-> C/C++->Code Generation-> Runtime Library. The issue got resolved when for all the projects there was common Runtime Library.

    2. The second error was because of the mixing of different types of configuration and platform. I had my C# code in 64 bit format and C++ code in 32 bit, which was creating ambiguity.


  2. There are two solutions here. The first is a dumb method and may not meet your needs. The second method you need to understand how to use COM components.

    Solution 1: You can compile them all to win32 and you can run successfully.

    Solution 2: You can write another 32bit dcom component (dll) to call your 32bit dll, set this dcom component as out of process com, and let your 64bit program call it. This method is very reliable.

    Let me know if it doesn’t work.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search