Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2004

Tip: Looking for answers? Try searching our database.

C++ to C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike Carr - 17 Aug 2004 21:02 GMT
I know very little about COM, please excuse me.  I am trying to convert a c++ COM app to C# and I am having problems.  I cannot change FactoryExecMarshal.

My C++ client code
#import "FactoryExecMarshal.tlb" no_namespace

ITestExecPtr m_pTestExec;

long hr = m_pTestExec.CreateInstance("MyTestExec.TestExec");
fails for -2147467252

(within CreateInstance)
hr = CoCreateInstance(rclsid, pOuter, dwClsContext, __uuidof(IUnknown), reinterpret_cast<void**>(&pIUnknown));
if (FAILED(hr)) {
   return hr;
  }

  hr = OleRun(pIUnknown);

  if (SUCCEEDED(hr)) {
   hr = pIUnknown->QueryInterface(GetIID(), reinterpret_cast<void**>(&m_pInterface));   <===== FAILS HERE FOR -2147467262
  }

===============================================================================================My C# code looks like this.
public class TestExec : ITestExec
{
  public TestExec()   {
   }
   public int initializeTestApp(object wrapper, string resFile, string chksum, string comPort)    {
       return 0;
   }
   ........
}

public interface ITestExec{
   int initializeTestApp(object wrapper,string resFile, string chksum, string comPort);
   .......
}

======================úctoryExecMarshal.tlb
======================// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: FactoryExecMarshal.tlb

[
 uuid(D9D79818-7FF6-11D3-ABC0-0008C7D32DD0),
 version(1.0),
 helpstring("Wrapper 1.0 Type Library"),
 custom(DE77BA64-517C-11D1-A2DA-0000F8773CE9, 83951780),
 custom(DE77BA63-517C-11D1-A2DA-0000F8773CE9, 978982337)

]
library WRAPPERLib
{
   // TLib :     // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
   importlib("stdole2.tlb");

   // Forward declare all types defined in this typelib
   interface ITestExec;
   interface IWrapper;
   interface INv;

   [
     odl,
     uuid(D9D79824-7FF6-11D3-ABC0-0008C7D32DD0),
     helpstring("ITestExec Interface")
   ]
   interface ITestExec : IUnknown {
       [helpstring("method initializeTestApp")]
       HRESULT _stdcall initializeTestApp(
                       [in] IUnknown* wrapper,
                       [in] BSTR resFile,
                       [in] BSTR checkSum,
                       [in] BSTR comPort,
                       [out, retval] int* pVal);
       [helpstring("method pingPhone")]
       HRESULT _stdcall pingPhone([out, retval] int* pVal);
       [helpstring("method shutdownTestProcess")]
       HRESULT _stdcall shutdownTestProcess([out, retval] int* pVal);
       [helpstring("method getMfgBytes")]
       HRESULT _stdcall getMfgBytes(
                       [in] int byteOffset,
                       [in] int bytesToRead,
                       [out] unsigned char* buffer,
                       [out, retval] int* pVal);
       [helpstring("method setMfgBytes")]
       HRESULT _stdcall setMfgBytes(
                       [in] int byteOffset,
                       [in] int bytesToWrite,
                       [in] unsigned char* buffer,
                       [out, retval] int* pVal);
       [helpstring("method getHexEsn")]
       HRESULT _stdcall getHexEsn(
                       [out] unsigned long* esn,
                       [out, retval] int* pVal);
       [helpstring("method getMobileModel")]
       HRESULT _stdcall getMobileModel(
                       [out] unsigned short* mobModel,
                       [out, retval] int* pVal);
       [helpstring("method getDMSSVer")]
       HRESULT _stdcall getDMSSVer(
                       [out] BSTR* buffer,
                       [out, retval] int* pVal);
       [helpstring("method pingTest")]
       HRESULT _stdcall pingTest([out, retval] int* pVal);
       [helpstring("method setTestDebugLevel")]
       HRESULT _stdcall setTestDebugLevel([in] int debugLevel);
       [helpstring("method getTCLCommands")]
       HRESULT _stdcall getTCLCommands([out, retval] int* pVal);
       [helpstring("method sendTestTCL")]
       HRESULT _stdcall sendTestTCL(
                       [in] int transId,
                       [in] BSTR tclString,
                       [out, retval] int* pVal);
       [helpstring("method sendTestStart")]
       HRESULT _stdcall sendTestStart(
                       [in] int transId,
                       [in] BSTR tclString,
                       [in] BSTR scriptCheckSum,
                       [out, retval] int* pVal);
       [helpstring("method sendTestStop")]
       HRESULT _stdcall sendTestStop([out, retval] int* pVal);
       [helpstring("method getTestVer")]
       HRESULT _stdcall getTestVer(
                       [out] BSTR* testExecName,
                       [out] BSTR* testExecVersion);
       [helpstring("method setPowerSupply")]
       HRESULT _stdcall setPowerSupply(
                       [in] int onOff,
                       [out, retval] int* pVal);
       [helpstring("method getPowerSupplyInfo")]
       HRESULT _stdcall getPowerSupplyInfo(
                       [out] BSTR* current,
                       [out] BSTR* voltage,
                       [out] BSTR* overVoltage,
                       [out, retval] int* pVal);
       [helpstring("method getErrorMsg")]
       HRESULT _stdcall getErrorMsg(
                       [in] int errorCode,
                       [out] BSTR* errorDesc);
       [helpstring("method ManagePort")]
       HRESULT _stdcall ManagePort(
                       [in] BSTR comPort,
                       [in] enManagePort portChange,
                       [out, retval] int* pVal);
   };

   typedef [public]
   __MIDL___MIDL_itf_FactoryExecMarshal_0000_0001 enManagePort;

   typedef enum {
       enOpenPort = 0,
       enClosePort = 1
   } __MIDL___MIDL_itf_FactoryExecMarshal_0000_0001;

   [
     odl,
     uuid(FB5FFFE3-6718-11D3-ABBE-0008C7D32DD0),
     helpstring("IWrapper Interface")
   ]
   interface IWrapper : IUnknown {
       [helpstring("method sendTestData")]
       HRESULT _stdcall sendTestData(
                       [in] int transId,
                       [in] BSTR functionName,
                       [in] int loopCntr,
                       [in] BSTR value,
                       [in] BSTR upper,
                       [in] BSTR lower,
                       [in] BSTR unit,
                       [in] BSTR dataType,
                       [in] BSTR failureDescription,
                       [in] int significantTestData,
                       [in] BSTR passFailCode);
       [helpstring("method sendTestDebug")]
       HRESULT _stdcall sendTestDebug(
                       [in] int transId,
                       [in] int debugLevel,
                       [in] BSTR debugMsg);
       [helpstring("method sendTestMsg")]
       HRESULT _stdcall sendTestMsg(
                       [in] int transId,
                       [in] BSTR message);
       [helpstring("method sendTestStatus")]
       HRESULT _stdcall sendTestStatus(
                       [in] int transId,
                       [in] BSTR functionName,
                       [in] int percentCompleted);
       [helpstring("method sendTestComplete")]
       HRESULT _stdcall sendTestComplete([in] int transId);
       [helpstring("method sendTCLCommand")]
       HRESULT _stdcall sendTCLCommand(
                       [in] int transId,
                       [in] BSTR supportedCommand);
       [helpstring("method exchangeData")]
       HRESULT _stdcall exchangeData(
                       [in] int transId,
                       [in] int dataRequest,
                       [in, out] VARIANT* varData);
   };

   [
     odl,
     uuid(1CE0BF5C-A156-11D4-BFC3-0008C78F17BD),
     helpstring("INv Interface")
   ]
   interface INv : IUnknown {
       [helpstring("method GetNvItem")]
       HRESULT _stdcall GetNvItem(
                       [in] unsigned short itemId,
                       [in] unsigned char param,
                       [out] unsigned char* buffer,
                       short* status,
                       int* pVal);
       [helpstring("method SetNvItem")]
       HRESULT _stdcall SetNvItem(
                       [in] unsigned short itemId,
                       [in] unsigned char* buffer,
                       short* status,
                       int* pVal);
   };
};

Signature

MICHAEL CARR

Bart Jacobs - 18 Aug 2004 05:48 GMT
-2147467262 = 0x80004002 = E_NOINTERFACE = "The QueryInterface method did
not recognize the requested interface. The interface is not supported."

I understand that you generate the FactoryExecMarshal.tlb from the C#
assembly? Since you do not specify an IID in your C# source code, an IID is
generated automatically under the hoods. Make sure that the IID that is
compiled into your C++ client binary is the same as the one recognized by
the C# server component.

I know very little about COM, please excuse me.  I am trying to convert a
c++ COM app to C# and I am having problems.  I cannot change
FactoryExecMarshal.

My C++ client code
#import "FactoryExecMarshal.tlb" no_namespace

ITestExecPtr m_pTestExec;

long hr = m_pTestExec.CreateInstance("MyTestExec.TestExec");
fails for -2147467252

(within CreateInstance)
hr = CoCreateInstance(rclsid, pOuter, dwClsContext, __uuidof(IUnknown),
reinterpret_cast<void**>(&pIUnknown));
if (FAILED(hr)) {
   return hr;
  }

  hr = OleRun(pIUnknown);

  if (SUCCEEDED(hr)) {
   hr = pIUnknown->QueryInterface(GetIID(),
reinterpret_cast<void**>(&m_pInterface));   <===== FAILS HERE
FOR -2147467262
  }

================================================================================================
My C# code looks like this.
public class TestExec : ITestExec
{
  public TestExec()   {
   }
   public int initializeTestApp(object wrapper, string resFile, string
chksum, string comPort)    {
       return 0;
   }
   ........
}

public interface ITestExec{
   int initializeTestApp(object wrapper,string resFile, string chksum,
string comPort);
   .......
}

========================
FactoryExecMarshal.tlb
========================

// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: FactoryExecMarshal.tlb

[
 uuid(D9D79818-7FF6-11D3-ABC0-0008C7D32DD0),
 version(1.0),
 helpstring("Wrapper 1.0 Type Library"),
 custom(DE77BA64-517C-11D1-A2DA-0000F8773CE9, 83951780),
 custom(DE77BA63-517C-11D1-A2DA-0000F8773CE9, 978982337)

]
library WRAPPERLib
{
   // TLib :     // TLib : OLE Automation :
{00020430-0000-0000-C000-000000000046}
   importlib("stdole2.tlb");

   // Forward declare all types defined in this typelib
   interface ITestExec;
   interface IWrapper;
   interface INv;

   [
     odl,
     uuid(D9D79824-7FF6-11D3-ABC0-0008C7D32DD0),
     helpstring("ITestExec Interface")
   ]
   interface ITestExec : IUnknown {
       [helpstring("method initializeTestApp")]
       HRESULT _stdcall initializeTestApp(
                       [in] IUnknown* wrapper,
                       [in] BSTR resFile,
                       [in] BSTR checkSum,
                       [in] BSTR comPort,
                       [out, retval] int* pVal);
       [helpstring("method pingPhone")]
       HRESULT _stdcall pingPhone([out, retval] int* pVal);
       [helpstring("method shutdownTestProcess")]
       HRESULT _stdcall shutdownTestProcess([out, retval] int* pVal);
       [helpstring("method getMfgBytes")]
       HRESULT _stdcall getMfgBytes(
                       [in] int byteOffset,
                       [in] int bytesToRead,
                       [out] unsigned char* buffer,
                       [out, retval] int* pVal);
       [helpstring("method setMfgBytes")]
       HRESULT _stdcall setMfgBytes(
                       [in] int byteOffset,
                       [in] int bytesToWrite,
                       [in] unsigned char* buffer,
                       [out, retval] int* pVal);
       [helpstring("method getHexEsn")]
       HRESULT _stdcall getHexEsn(
                       [out] unsigned long* esn,
                       [out, retval] int* pVal);
       [helpstring("method getMobileModel")]
       HRESULT _stdcall getMobileModel(
                       [out] unsigned short* mobModel,
                       [out, retval] int* pVal);
       [helpstring("method getDMSSVer")]
       HRESULT _stdcall getDMSSVer(
                       [out] BSTR* buffer,
                       [out, retval] int* pVal);
       [helpstring("method pingTest")]
       HRESULT _stdcall pingTest([out, retval] int* pVal);
       [helpstring("method setTestDebugLevel")]
       HRESULT _stdcall setTestDebugLevel([in] int debugLevel);
       [helpstring("method getTCLCommands")]
       HRESULT _stdcall getTCLCommands([out, retval] int* pVal);
       [helpstring("method sendTestTCL")]
       HRESULT _stdcall sendTestTCL(
                       [in] int transId,
                       [in] BSTR tclString,
                       [out, retval] int* pVal);
       [helpstring("method sendTestStart")]
       HRESULT _stdcall sendTestStart(
                       [in] int transId,
                       [in] BSTR tclString,
                       [in] BSTR scriptCheckSum,
                       [out, retval] int* pVal);
       [helpstring("method sendTestStop")]
       HRESULT _stdcall sendTestStop([out, retval] int* pVal);
       [helpstring("method getTestVer")]
       HRESULT _stdcall getTestVer(
                       [out] BSTR* testExecName,
                       [out] BSTR* testExecVersion);
       [helpstring("method setPowerSupply")]
       HRESULT _stdcall setPowerSupply(
                       [in] int onOff,
                       [out, retval] int* pVal);
       [helpstring("method getPowerSupplyInfo")]
       HRESULT _stdcall getPowerSupplyInfo(
                       [out] BSTR* current,
                       [out] BSTR* voltage,
                       [out] BSTR* overVoltage,
                       [out, retval] int* pVal);
       [helpstring("method getErrorMsg")]
       HRESULT _stdcall getErrorMsg(
                       [in] int errorCode,
                       [out] BSTR* errorDesc);
       [helpstring("method ManagePort")]
       HRESULT _stdcall ManagePort(
                       [in] BSTR comPort,
                       [in] enManagePort portChange,
                       [out, retval] int* pVal);
   };

   typedef [public]
   __MIDL___MIDL_itf_FactoryExecMarshal_0000_0001 enManagePort;

   typedef enum {
       enOpenPort = 0,
       enClosePort = 1
   } __MIDL___MIDL_itf_FactoryExecMarshal_0000_0001;

   [
     odl,
     uuid(FB5FFFE3-6718-11D3-ABBE-0008C7D32DD0),
     helpstring("IWrapper Interface")
   ]
   interface IWrapper : IUnknown {
       [helpstring("method sendTestData")]
       HRESULT _stdcall sendTestData(
                       [in] int transId,
                       [in] BSTR functionName,
                       [in] int loopCntr,
                       [in] BSTR value,
                       [in] BSTR upper,
                       [in] BSTR lower,
                       [in] BSTR unit,
                       [in] BSTR dataType,
                       [in] BSTR failureDescription,
                       [in] int significantTestData,
                       [in] BSTR passFailCode);
       [helpstring("method sendTestDebug")]
       HRESULT _stdcall sendTestDebug(
                       [in] int transId,
                       [in] int debugLevel,
                       [in] BSTR debugMsg);
       [helpstring("method sendTestMsg")]
       HRESULT _stdcall sendTestMsg(
                       [in] int transId,
                       [in] BSTR message);
       [helpstring("method sendTestStatus")]
       HRESULT _stdcall sendTestStatus(
                       [in] int transId,
                       [in] BSTR functionName,
                       [in] int percentCompleted);
       [helpstring("method sendTestComplete")]
       HRESULT _stdcall sendTestComplete([in] int transId);
       [helpstring("method sendTCLCommand")]
       HRESULT _stdcall sendTCLCommand(
                       [in] int transId,
                       [in] BSTR supportedCommand);
       [helpstring("method exchangeData")]
       HRESULT _stdcall exchangeData(
                       [in] int transId,
                       [in] int dataRequest,
                       [in, out] VARIANT* varData);
   };

   [
     odl,
     uuid(1CE0BF5C-A156-11D4-BFC3-0008C78F17BD),
     helpstring("INv Interface")
   ]
   interface INv : IUnknown {
       [helpstring("method GetNvItem")]
       HRESULT _stdcall GetNvItem(
                       [in] unsigned short itemId,
                       [in] unsigned char param,
                       [out] unsigned char* buffer,
                       short* status,
                       int* pVal);
       [helpstring("method SetNvItem")]
       HRESULT _stdcall SetNvItem(
                       [in] unsigned short itemId,
                       [in] unsigned char* buffer,
                       short* status,
                       int* pVal);
   };
};

Signature

MICHAEL CARR

Mike Carr - 18 Aug 2004 16:32 GMT
Actually FactoryExecMarshal.tld is generated by a C++ application.
How do I specify an IID in the c# code?

Thanks,
Mike Carr

Signature

MICHAEL CARR

> -2147467262 = 0x80004002 = E_NOINTERFACE = "The QueryInterface method did
> not recognize the requested interface. The interface is not supported."
[quoted text clipped - 31 lines]
> FOR -2147467262
>    }

============================================================================
====================
> My C# code looks like this.
> public class TestExec : ITestExec
[quoted text clipped - 201 lines]
>     };
> };
Mike Carr - 20 Aug 2004 19:08 GMT
When I use a regular C++ application I see it loading

+ &clsid 0x0012fc00 {CLSID_TestExec Class} _GUID *

But when I run my C# version I see

+ &clsid 0x0012fc20 {CLSID_MyTestExec.TestExec} _GUID *

Does anyone know how to get it to look like the C++?

Signature

MICHAEL CARR

 I know very little about COM, please excuse me.  I am trying to convert a c++ COM app to C# and I am having problems.  I cannot change FactoryExecMarshal.

 My C++ client code
 #import "FactoryExecMarshal.tlb" no_namespace

 ITestExecPtr m_pTestExec;

 long hr = m_pTestExec.CreateInstance("MyTestExec.TestExec");
 fails for -2147467252

 (within CreateInstance)
 hr = CoCreateInstance(rclsid, pOuter, dwClsContext, __uuidof(IUnknown), reinterpret_cast<void**>(&pIUnknown));
 if (FAILED(hr)) {
     return hr;
    }

    hr = OleRun(pIUnknown);

    if (SUCCEEDED(hr)) {
     hr = pIUnknown->QueryInterface(GetIID(), reinterpret_cast<void**>(&m_pInterface));   <===== FAILS HERE FOR -2147467262
    }

 ===============================================================================================  My C# code looks like this.
 public class TestExec : ITestExec
 {
    public TestExec()   {
     }
     public int initializeTestApp(object wrapper, string resFile, string chksum, string comPort)    {
         return 0;
     }
     ........
 }

 public interface ITestExec{
     int initializeTestApp(object wrapper,string resFile, string chksum, string comPort);
     .......
 }

 =======================  FactoryExecMarshal.tlb
 ======================  // Generated .IDL file (by the OLE/COM Object Viewer)
 //
 // typelib filename: FactoryExecMarshal.tlb

 [
   uuid(D9D79818-7FF6-11D3-ABC0-0008C7D32DD0),
   version(1.0),
   helpstring("Wrapper 1.0 Type Library"),
   custom(DE77BA64-517C-11D1-A2DA-0000F8773CE9, 83951780),
   custom(DE77BA63-517C-11D1-A2DA-0000F8773CE9, 978982337)

 ]
 library WRAPPERLib
 {
     // TLib :     // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
     importlib("stdole2.tlb");

     // Forward declare all types defined in this typelib
     interface ITestExec;
     interface IWrapper;
     interface INv;

     [
       odl,
       uuid(D9D79824-7FF6-11D3-ABC0-0008C7D32DD0),
       helpstring("ITestExec Interface")
     ]
     interface ITestExec : IUnknown {
         [helpstring("method initializeTestApp")]
         HRESULT _stdcall initializeTestApp(
                         [in] IUnknown* wrapper,
                         [in] BSTR resFile,
                         [in] BSTR checkSum,
                         [in] BSTR comPort,
                         [out, retval] int* pVal);
         [helpstring("method pingPhone")]
         HRESULT _stdcall pingPhone([out, retval] int* pVal);
         [helpstring("method shutdownTestProcess")]
         HRESULT _stdcall shutdownTestProcess([out, retval] int* pVal);
         [helpstring("method getMfgBytes")]
         HRESULT _stdcall getMfgBytes(
                         [in] int byteOffset,
                         [in] int bytesToRead,
                         [out] unsigned char* buffer,
                         [out, retval] int* pVal);
         [helpstring("method setMfgBytes")]
         HRESULT _stdcall setMfgBytes(
                         [in] int byteOffset,
                         [in] int bytesToWrite,
                         [in] unsigned char* buffer,
                         [out, retval] int* pVal);
         [helpstring("method getHexEsn")]
         HRESULT _stdcall getHexEsn(
                         [out] unsigned long* esn,
                         [out, retval] int* pVal);
         [helpstring("method getMobileModel")]
         HRESULT _stdcall getMobileModel(
                         [out] unsigned short* mobModel,
                         [out, retval] int* pVal);
         [helpstring("method getDMSSVer")]
         HRESULT _stdcall getDMSSVer(
                         [out] BSTR* buffer,
                         [out, retval] int* pVal);
         [helpstring("method pingTest")]
         HRESULT _stdcall pingTest([out, retval] int* pVal);
         [helpstring("method setTestDebugLevel")]
         HRESULT _stdcall setTestDebugLevel([in] int debugLevel);
         [helpstring("method getTCLCommands")]
         HRESULT _stdcall getTCLCommands([out, retval] int* pVal);
         [helpstring("method sendTestTCL")]
         HRESULT _stdcall sendTestTCL(
                         [in] int transId,
                         [in] BSTR tclString,
                         [out, retval] int* pVal);
         [helpstring("method sendTestStart")]
         HRESULT _stdcall sendTestStart(
                         [in] int transId,
                         [in] BSTR tclString,
                         [in] BSTR scriptCheckSum,
                         [out, retval] int* pVal);
         [helpstring("method sendTestStop")]
         HRESULT _stdcall sendTestStop([out, retval] int* pVal);
         [helpstring("method getTestVer")]
         HRESULT _stdcall getTestVer(
                         [out] BSTR* testExecName,
                         [out] BSTR* testExecVersion);
         [helpstring("method setPowerSupply")]
         HRESULT _stdcall setPowerSupply(
                         [in] int onOff,
                         [out, retval] int* pVal);
         [helpstring("method getPowerSupplyInfo")]
         HRESULT _stdcall getPowerSupplyInfo(
                         [out] BSTR* current,
                         [out] BSTR* voltage,
                         [out] BSTR* overVoltage,
                         [out, retval] int* pVal);
         [helpstring("method getErrorMsg")]
         HRESULT _stdcall getErrorMsg(
                         [in] int errorCode,
                         [out] BSTR* errorDesc);
         [helpstring("method ManagePort")]
         HRESULT _stdcall ManagePort(
                         [in] BSTR comPort,
                         [in] enManagePort portChange,
                         [out, retval] int* pVal);
     };

     typedef [public]
     __MIDL___MIDL_itf_FactoryExecMarshal_0000_0001 enManagePort;

     typedef enum {
         enOpenPort = 0,
         enClosePort = 1
     } __MIDL___MIDL_itf_FactoryExecMarshal_0000_0001;

     [
       odl,
       uuid(FB5FFFE3-6718-11D3-ABBE-0008C7D32DD0),
       helpstring("IWrapper Interface")
     ]
     interface IWrapper : IUnknown {
         [helpstring("method sendTestData")]
         HRESULT _stdcall sendTestData(
                         [in] int transId,
                         [in] BSTR functionName,
                         [in] int loopCntr,
                         [in] BSTR value,
                         [in] BSTR upper,
                         [in] BSTR lower,
                         [in] BSTR unit,
                         [in] BSTR dataType,
                         [in] BSTR failureDescription,
                         [in] int significantTestData,
                         [in] BSTR passFailCode);
         [helpstring("method sendTestDebug")]
         HRESULT _stdcall sendTestDebug(
                         [in] int transId,
                         [in] int debugLevel,
                         [in] BSTR debugMsg);
         [helpstring("method sendTestMsg")]
         HRESULT _stdcall sendTestMsg(
                         [in] int transId,
                         [in] BSTR message);
         [helpstring("method sendTestStatus")]
         HRESULT _stdcall sendTestStatus(
                         [in] int transId,
                         [in] BSTR functionName,
                         [in] int percentCompleted);
         [helpstring("method sendTestComplete")]
         HRESULT _stdcall sendTestComplete([in] int transId);
         [helpstring("method sendTCLCommand")]
         HRESULT _stdcall sendTCLCommand(
                         [in] int transId,
                         [in] BSTR supportedCommand);
         [helpstring("method exchangeData")]
         HRESULT _stdcall exchangeData(
                         [in] int transId,
                         [in] int dataRequest,
                         [in, out] VARIANT* varData);
     };

     [
       odl,
       uuid(1CE0BF5C-A156-11D4-BFC3-0008C78F17BD),
       helpstring("INv Interface")
     ]
     interface INv : IUnknown {
         [helpstring("method GetNvItem")]
         HRESULT _stdcall GetNvItem(
                         [in] unsigned short itemId,
                         [in] unsigned char param,
                         [out] unsigned char* buffer,
                         short* status,
                         int* pVal);
         [helpstring("method SetNvItem")]
         HRESULT _stdcall SetNvItem(
                         [in] unsigned short itemId,
                         [in] unsigned char* buffer,
                         short* status,
                         int* pVal);
     };
 };

 --
 MICHAEL CARR
Mike Carr - 02 Sep 2004 16:19 GMT
No solution found for this one yet

Signature

MICHAEL CARR

 When I use a regular C++ application I see it loading

 + &clsid 0x0012fc00 {CLSID_TestExec Class} _GUID *

 But when I run my C# version I see

 + &clsid 0x0012fc20 {CLSID_MyTestExec.TestExec} _GUID *

 Does anyone know how to get it to look like the C++?

 --
 MICHAEL CARR

   "Mike Carr" <mcarr@_san.rr.com> wrote in message news:umUUSUJhEHA.3236@TK2MSFTNGP10.phx.gbl...
   I know very little about COM, please excuse me.  I am trying to convert a c++ COM app to C# and I am having problems.  I cannot change FactoryExecMarshal.

   My C++ client code
   #import "FactoryExecMarshal.tlb" no_namespace

   ITestExecPtr m_pTestExec;

   long hr = m_pTestExec.CreateInstance("MyTestExec.TestExec");
   fails for -2147467252

   (within CreateInstance)
   hr = CoCreateInstance(rclsid, pOuter, dwClsContext, __uuidof(IUnknown), reinterpret_cast<void**>(&pIUnknown));
   if (FAILED(hr)) {
       return hr;
      }

      hr = OleRun(pIUnknown);

      if (SUCCEEDED(hr)) {
       hr = pIUnknown->QueryInterface(GetIID(), reinterpret_cast<void**>(&m_pInterface));   <===== FAILS HERE FOR -2147467262
      }

   ===============================================================================================    My C# code looks like this.
   public class TestExec : ITestExec
   {
      public TestExec()   {
       }
       public int initializeTestApp(object wrapper, string resFile, string chksum, string comPort)    {
           return 0;
       }
       ........
   }

   public interface ITestExec{
       int initializeTestApp(object wrapper,string resFile, string chksum, string comPort);
       .......
   }

   =======================    FactoryExecMarshal.tlb
   ======================    // Generated .IDL file (by the OLE/COM Object Viewer)
   //
   // typelib filename: FactoryExecMarshal.tlb

   [
     uuid(D9D79818-7FF6-11D3-ABC0-0008C7D32DD0),
     version(1.0),
     helpstring("Wrapper 1.0 Type Library"),
     custom(DE77BA64-517C-11D1-A2DA-0000F8773CE9, 83951780),
     custom(DE77BA63-517C-11D1-A2DA-0000F8773CE9, 978982337)

   ]
   library WRAPPERLib
   {
       // TLib :     // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
       importlib("stdole2.tlb");

       // Forward declare all types defined in this typelib
       interface ITestExec;
       interface IWrapper;
       interface INv;

       [
         odl,
         uuid(D9D79824-7FF6-11D3-ABC0-0008C7D32DD0),
         helpstring("ITestExec Interface")
       ]
       interface ITestExec : IUnknown {
           [helpstring("method initializeTestApp")]
           HRESULT _stdcall initializeTestApp(
                           [in] IUnknown* wrapper,
                           [in] BSTR resFile,
                           [in] BSTR checkSum,
                           [in] BSTR comPort,
                           [out, retval] int* pVal);
           [helpstring("method pingPhone")]
           HRESULT _stdcall pingPhone([out, retval] int* pVal);
           [helpstring("method shutdownTestProcess")]
           HRESULT _stdcall shutdownTestProcess([out, retval] int* pVal);
           [helpstring("method getMfgBytes")]
           HRESULT _stdcall getMfgBytes(
                           [in] int byteOffset,
                           [in] int bytesToRead,
                           [out] unsigned char* buffer,
                           [out, retval] int* pVal);
           [helpstring("method setMfgBytes")]
           HRESULT _stdcall setMfgBytes(
                           [in] int byteOffset,
                           [in] int bytesToWrite,
                           [in] unsigned char* buffer,
                           [out, retval] int* pVal);
           [helpstring("method getHexEsn")]
           HRESULT _stdcall getHexEsn(
                           [out] unsigned long* esn,
                           [out, retval] int* pVal);
           [helpstring("method getMobileModel")]
           HRESULT _stdcall getMobileModel(
                           [out] unsigned short* mobModel,
                           [out, retval] int* pVal);
           [helpstring("method getDMSSVer")]
           HRESULT _stdcall getDMSSVer(
                           [out] BSTR* buffer,
                           [out, retval] int* pVal);
           [helpstring("method pingTest")]
           HRESULT _stdcall pingTest([out, retval] int* pVal);
           [helpstring("method setTestDebugLevel")]
           HRESULT _stdcall setTestDebugLevel([in] int debugLevel);
           [helpstring("method getTCLCommands")]
           HRESULT _stdcall getTCLCommands([out, retval] int* pVal);
           [helpstring("method sendTestTCL")]
           HRESULT _stdcall sendTestTCL(
                           [in] int transId,
                           [in] BSTR tclString,
                           [out, retval] int* pVal);
           [helpstring("method sendTestStart")]
           HRESULT _stdcall sendTestStart(
                           [in] int transId,
                           [in] BSTR tclString,
                           [in] BSTR scriptCheckSum,
                           [out, retval] int* pVal);
           [helpstring("method sendTestStop")]
           HRESULT _stdcall sendTestStop([out, retval] int* pVal);
           [helpstring("method getTestVer")]
           HRESULT _stdcall getTestVer(
                           [out] BSTR* testExecName,
                           [out] BSTR* testExecVersion);
           [helpstring("method setPowerSupply")]
           HRESULT _stdcall setPowerSupply(
                           [in] int onOff,
                           [out, retval] int* pVal);
           [helpstring("method getPowerSupplyInfo")]
           HRESULT _stdcall getPowerSupplyInfo(
                           [out] BSTR* current,
                           [out] BSTR* voltage,
                           [out] BSTR* overVoltage,
                           [out, retval] int* pVal);
           [helpstring("method getErrorMsg")]
           HRESULT _stdcall getErrorMsg(
                           [in] int errorCode,
                           [out] BSTR* errorDesc);
           [helpstring("method ManagePort")]
           HRESULT _stdcall ManagePort(
                           [in] BSTR comPort,
                           [in] enManagePort portChange,
                           [out, retval] int* pVal);
       };

       typedef [public]
       __MIDL___MIDL_itf_FactoryExecMarshal_0000_0001 enManagePort;

       typedef enum {
           enOpenPort = 0,
           enClosePort = 1
       } __MIDL___MIDL_itf_FactoryExecMarshal_0000_0001;

       [
         odl,
         uuid(FB5FFFE3-6718-11D3-ABBE-0008C7D32DD0),
         helpstring("IWrapper Interface")
       ]
       interface IWrapper : IUnknown {
           [helpstring("method sendTestData")]
           HRESULT _stdcall sendTestData(
                           [in] int transId,
                           [in] BSTR functionName,
                           [in] int loopCntr,
                           [in] BSTR value,
                           [in] BSTR upper,
                           [in] BSTR lower,
                           [in] BSTR unit,
                           [in] BSTR dataType,
                           [in] BSTR failureDescription,
                           [in] int significantTestData,
                           [in] BSTR passFailCode);
           [helpstring("method sendTestDebug")]
           HRESULT _stdcall sendTestDebug(
                           [in] int transId,
                           [in] int debugLevel,
                           [in] BSTR debugMsg);
           [helpstring("method sendTestMsg")]
           HRESULT _stdcall sendTestMsg(
                           [in] int transId,
                           [in] BSTR message);
           [helpstring("method sendTestStatus")]
           HRESULT _stdcall sendTestStatus(
                           [in] int transId,
                           [in] BSTR functionName,
                           [in] int percentCompleted);
           [helpstring("method sendTestComplete")]
           HRESULT _stdcall sendTestComplete([in] int transId);
           [helpstring("method sendTCLCommand")]
           HRESULT _stdcall sendTCLCommand(
                           [in] int transId,
                           [in] BSTR supportedCommand);
           [helpstring("method exchangeData")]
           HRESULT _stdcall exchangeData(
                           [in] int transId,
                           [in] int dataRequest,
                           [in, out] VARIANT* varData);
       };

       [
         odl,
         uuid(1CE0BF5C-A156-11D4-BFC3-0008C78F17BD),
         helpstring("INv Interface")
       ]
       interface INv : IUnknown {
           [helpstring("method GetNvItem")]
           HRESULT _stdcall GetNvItem(
                           [in] unsigned short itemId,
                           [in] unsigned char param,
                           [out] unsigned char* buffer,
                           short* status,
                           int* pVal);
           [helpstring("method SetNvItem")]
           HRESULT _stdcall SetNvItem(
                           [in] unsigned short itemId,
                           [in] unsigned char* buffer,
                           short* status,
                           int* pVal);
       };
   };

   --
   MICHAEL CARR

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.