Community discussion forum

C# dll called from C++ app GPF

  • 4 years ago

    This is a little difficult to explain. I created a dll in .NET using C# and I need to call this dll from a Visual C++ 6.0 application. I read numerous materials on setting the C# dll up with COM Interop and I think I have it working. Now for the difficult part: when I call the function to launch the UI in the C# dll, it comes up, then I do my thing and close it down. I then go through the functionality again and the dll is called w/ no problems, the form comes up, etc. When I close it down, I will get a GPF. In trying to trace the problem, it returns from my dll, then returns from my function in the 6.0 c++ application, and returns from another function. I cannot discover where the GPF is occurring. Here is a basic outline of my 6.0 c++ function:


    void functionname
    {
    // Initialize COM.
    HRESULT hr = CoInitialize(NULL);


    // Create the interface pointer.
    IManageInterfacePtr pIInterface(__uuidof(ManagerInterface));


    // Call the Add method.
    pIInterface->LaunchRSSDLL(string, string, string);


    pIInterface->Dispose(); <--this is from trying something with the C# dll


    pIInterface->Release();


    // Uninitialize COM.
    CoUninitialize();
    }


    I have put try/catch inside this function, around the call to this function, inside my C# DLL COM interface, and I still cannot find where the gpf is occurring. This is my first C# dll so be please be patient if I so kind of idiotic in describing this. Any ideas on what I may be missing? Any ideas on what I can look at?

  • 4 years ago

    I found the answer to my problem:


    http://www.dotnet247.com/247referen.../35/178790.aspx


    I removed the EnableVisualStyles() call from my .NET dll and the unhandled exception has not been encountered.

  • 4 years ago
    Hello,

    I am facing a similiar problem but haven't figured out about it. Maybe you can help or share the experience:


    This is my problem:

    I have C# project compiled as a DLL. The C# class is defined as:

    public Cs_Class
    {
    String name;
    public Cs_Class(String n)
    { name = n; }

    ....
    }

    I have another MC++ project that uses the DLL. The MC++ class is defined as:

    public Cpp_Class
    {
      ....
      void Test(String* testStr)
      {
            //Create the c# class
            //
            Cs_Class* c = new Cs_Class(testStr);
      }

    }


    The compilation/linking was fine. I then encountered a run-time exception:

    System.MissingMethodException: Method not found: Cs_Class..ctor(System.String)...

    Strangly enough, if I took out the String parameter in Cs_Class constructor and not pass in String* in MC++ class when constructing the Cs_Class object, then everything was fine.

    Why??

    Thanks in advance.

    David




    Quote:
    [1]Posted by Al_Pennyworth on 17 Mar 2005 06:15 PM[/1]
    This is a little difficult to explain. I created a dll in .NET using C# and I need to call this dll from a Visual C++ 6.0 application. I read numerous materials on setting the C# dll up with COM Interop and I think I have it working. Now for the difficult part: when I call the function to launch the UI in the C# dll, it comes up, then I do my thing and close it down. I then go through the functionality again and the dll is called w/ no problems, the form comes up, etc. When I close it down, I will get a GPF. In trying to trace the problem, it returns from my dll, then returns from my function in the 6.0 c++ application, and returns from another function. I cannot discover where the GPF is occurring. Here is a basic outline of my 6.0 c++ function:

    void functionname
    {
    // Initialize COM.
    HRESULT hr = CoInitialize(NULL);

    // Create the interface pointer.
    IManageInterfacePtr pIInterface(__uuidof(ManagerInterface));

    // Call the Add method.
    pIInterface->LaunchRSSDLL(string, string, string);

    pIInterface->Dispose(); <--this is from trying something with the C# dll

    pIInterface->Release();

    // Uninitialize COM.
    CoUninitialize();
    }

    I have put try/catch inside this function, around the call to this function, inside my C# DLL COM interface, and I still cannot find where the gpf is occurring. This is my first C# dll so be please be patient if I so kind of idiotic in describing this. Any ideas on what I may be missing? Any ideas on what I can look at?

  • 1 year ago

    dahhhhhhhhhhhhhhhhhhhhhhh

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback