CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2010

    Calling CoCreateInstance in C# (C++ to C# migration)

    Hi all,

    I am migrating some code from C++ to a C# WebService, and specifically I use CoCreateInstance in the C++ code. I have two questions that interests me:

    1) Is it possible to integrate a C++ code into the C# code?

    2) If not, is there an equivalent CoCreateInstance in C#?

    For more info, I import two files which are #include "SmsMsgAPI.h", #include "SmsMsgAPI_i.c". Then the CoCreateInstance looks like this:

    sLocationRequest = sNewLocationRequest.AllocSysString();

    sMPIPAddress = sMPIP.AllocSysString();



    //Create root messaging object

    _CHECKHR( ::CoCreateInstance(





    (LPVOID*)&pMessaging) );

    //Create message object for request

    _CHECKHR( pMessaging->CreateMessage(&pRequest) );

    //Set the target of the message to the Location Manager endpoint

    _CHECKHR( pRequest->SetTargetEndpoint(L"MP_LocationManager") );

    //Set the message body with the request

    _CHECKHR( pRequest->SetBodyFromString(sLocationRequest) );

    // Invoke the targeted endpoint on the local machine with the request,

    // and retrieve the reply.

    _CHECKHR( pMessaging->Invoke(sMPIPAddress, pRequest, &pReply) );

    // Extract body from reply message.

    _CHECKHR( pReply->GetBodyToString(&pszReplyMessage) );

    wprintf(L"\n\nReply from MP:\n%s", (wchar_t *) pszReplyMessage);


    Thank you in advance!

  2. #2
    Join Date
    Mar 2010

    Re: Calling CoCreateInstance in C# (C++ to C# migration)

    Hi, I finally solved this problem:

    Here is a link that helped me with how to use the Management Point API in C# : http://msdn.microsoft.com/en-us/library/cc144347.aspx and http://blogs.msdn.com/b/gabeb/archiv...et-part-1.aspx.

Tags for this Thread

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)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.