.NET Framework Developer Center > .NET Development Forums > Common Language Runtime > Interoperability from C++ 6.0 to a C# COM component
Ask a questionAsk a question
 

QuestionInteroperability from C++ 6.0 to a C# COM component

  • Friday, November 06, 2009 4:46 PMAndster Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi,
    I have a big legacy c++ 6.0 application that I want to access some C# code.

    I have made the c# code into a COM component. I have the C++ code initializing COM, importing the COM component, and successfully creating an instance of the COM component.

    However, when I make my first call to the COM component, it returns an Invalid Pointer error. The call includes a string parameter that the COM component is to change. I have tried searching MSDN for information and tried several of  the methods I have come across, but they all result in an Invalid Pointer. I would appreciate any help on this, or a link to information about it.

    The C++ code looks like this: 

        int nResult;
        long nComResult = 0;
        long TasRetVal = 0;
        BOOL bRetVal = SUCCESS;
        CHAR LogMsg[255] = {0};   
        BSTR sTasResult = SysAllocString(L"");
        CComBSTR bstrXMLResult;

        STRING sContextPath = "";
        STRING sXMLResult = "";

        CTasContextProvider OTasContextProvider;

        EXTLOG("Inside CreateTasAdjustment");

        if (BAL_ROLE::TasEnginePtr != NULL)
        {
            EXTLOG("About to call Start engine of TAS");
            nComResult = BAL_ROLE::TasEnginePtr->Start(AdjstId, &TasRetVal, &sTasResult);
            if (nComResult != 0)
           {
               sprintf(LogMsg,"TasEnginePtr->Start has returned error <%ld>. Aborting the adjustment.", nComResult);
               EXTLOG(LogMsg);
               IDT_ROLE::ShowMessage(SEVERITY_INFO, "The adjustment service failed, Please try the adjustment again.");

               goto Cleanup;
           }
           ...

    The definition of the function in the COM component is:

          public void Start(int adjID, out int retValue, out string resultData)//iteration-4

          {

    Thanks.

All Replies

  • Sunday, November 08, 2009 11:40 PMAndster Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I found this eerily similar issue on a different forum: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/85dbe450-1b74-424a-aa70-4a0416fe0532/

    Does anyone think my problem may be the same as that problem?

  • Monday, November 09, 2009 10:37 AMJialiang Ge [MSFT]MSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello

    By "Invalid Pointer", do you mean NULL or a pointer that points to some garbage data or inaccessible memory? Does TasRetVal return the right value?

    The possibly best method to diagnose this problem is to debug the application in mixed mode.
    http://msdn.microsoft.com/en-us/library/kbaht4dh.aspx
    In this way, you are able to trace across the native and .NET boundaries, and see where the output is not set rightly.
    Regards,
    Jialiang Ge
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Tuesday, November 10, 2009 2:09 PMAndster Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi, By "Invalid Pointer", I mean that -2147467261 is being returned into my nTasResult variable. I believe that value is the Invalid Pointer error code. The values of TasRetVal and TasResult are unchanged. I tried debugging it with VS 2008. I never get to the Start function in the COM component. The Invalid Pointer seems to be detected and returned by the layers between my mananaged and unmanaged code before they get to my COM component. In the meantime, I have discovered that: 1. If I build the COM component on a different machine, I don't get the Invalid Pointer error. Instead, I get an access violation in the layers between my managed and unmanaged code. 2. If I use a Debug build of the COM component the problem does not occur. Things work fine. If I use a Release build of the COM component, the Invalid Pointer error is returned. These findings make me think that memory corruption is occurring, just like someone mentioned in the link I attached to my last post here. I am continuing to investigate, but there is a lot of code involved.
  • Thursday, November 12, 2009 10:16 AMJialiang Ge [MSFT]MSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello

    I'd like to assist you to investigate the problem, if you could narrow the problem down to a sample project that can be shared with me to reproduce the issue. My email address is jialge@microsoft.com.
    Regards,
    Jialiang Ge
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Monday, November 23, 2009 7:38 AMJialiang Ge [MSFT]MSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    We are changing the issue type to “General Discussion” because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question” by opening the Options list at the top of the post window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.
    Regards,
    Jialiang Ge
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Wednesday, November 25, 2009 9:36 PMAndster Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Sorry, I got side-tracked for a couple of weeks.

    I am still very interested in getting help for this problem.

    I had one of the developers try to reproduce the same circumstances in a small project, but the problem does not occur. I have taken his project and I am enhancing it to more closely reproduce the conditions of the original code. I will post the results when I get some.

  • Wednesday, November 25, 2009 11:12 PMAndster Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    btw, I thought I would get an email when others post to this issue. I have an alert set for it.