dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Calling Visual Studio DLL in a C# program

  1. #1
    Join Date
    Dec 2019
    Posts
    4

    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

  2. #2
    Join Date
    Dec 2019
    Posts
    4

    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

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,208

    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.

  4. #4
    Join Date
    Dec 2019
    Posts
    5

    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

  5. #5
    Join Date
    Dec 2019
    Posts
    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)