I'm trying to create a COM Wrapper to an existing .net Lib.
Nothing seems to work from a COM perspective. I started "walking" back until nothing of my code remained
I tried a basic C++ COM client pointing to a sample .net Server to figure out if the COM interop was working.
I can __uuidof() and get the propper UUID, but createIntance in _com_ptr_t returns Class Not Registered, and point to IPtr is null.
c++ client:
#include <iostream>
#define _WIN32_DCOM
#import "..\\bin\\Debug\\TestServer.tlb"
using namespace TestServer;
int main()
{
std::cout << "Hello, World!";
TestServer::_Numbers *com_ptr;
CoInitialize(NULL);
TestServer::_NumbersPtr p(__uuidof(TestServer::Numbers));
com_ptr = p;
int m_iDay = com_ptr->GetDay();
std::cout << m_iDay;
return 0;
}
the .Net Server:
using System;
using System.Runtime.InteropServices;
namespace TestServer
{
[Guid("D6F88E95-8A27-4ae6-B6DE-0542A0FC7039")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface _Numbers
{
[DispId(1)]
int GetDay();
}
[Guid("13FE32AD-4BF8-495f-AB4D-6C61BD463EA4")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("Tester.Numbers")]
public class Numbers : _Numbers
{
public Numbers(){}
public int GetDay()
{
return(DateTime.Today.Day);
}
}
}
I've check and oleView can get the TypeLib, that is as follows:
// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: TestServer.tlb
[
uuid(AB9E360D-4B96-32C2-AB45-66E4A99A5FF0),
version(1.0),
custom(90883F05-3D28-11D2-8F17-00A0C9A6186D, "TestServer, Version=1.0.6670.3022, Culture=neutral, PublicKeyToken=null")
]
library TestServer
{
// TLib : mscorlib.dll : {BED7F4EA-1A96-11D2-8F08-00A0C9A6186D}
importlib("mscorlib.tlb");
// TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");
// Forward declare all types defined in this typelib
dispinterface _Numbers;
[
uuid(D6F88E95-8A27-4AE6-B6DE-0542A0FC7039),
version(1.0),
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "TestServer._Numbers")
]
dispinterface _Numbers {
properties:
methods:
[id(0x00000001)]
long GetDay();
};
[
uuid(13FE32AD-4BF8-495F-AB4D-6C61BD463EA4),
version(1.0),
custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "TestServer.Numbers")
]
coclass Numbers {
interface _Object;
[default] dispinterface _Numbers;
};
};
What am i missing?
Can this be something related to OS (Win 7 Ultimate x64)?
Garbage on GACL?
How do I cleanup?
Thanks in advance. Any comment is helpfull as I can't seem to sort this out. Focus should be on my project and not on COM basics
THANKS
Credits: Sample code reused from Nick Parker (https://www.codeproject.com/Articles/3511/Exposing-NET-Components-to-COM#mfc)
User contributions licensed under CC BY-SA 3.0