Calling C# COM Dll from Managed C

T

Tim Nelson

Can you lend a hand?
Newbie here ....trying to call a C# COM object (error is below):

****** C# DLL ********

namespace ECSLink
{
public class ECSInvoke
{
public void PrintString(string strName)
{
System.Console.WriteLine("Hello from COM");
}
}
}

Built via:

csc /target:library /out:ECSLink.dll ECSLink.cs
tlbexp ECSLink.dll /verbose

****** C Code *******

#import "ECSLink.tlb"

int main(int argc, char* argv[])
{
CoInitialize(NULL);
ECSInvokePtr ob;
ob->CreateInstance(__uuidof(ECSInvoke));
ob->PrintString();
return 0;
}

ERROR return from: cl client.cpp.....

client.cpp
client.cpp(6) : error C2065: 'ECSInvokePtr' : undeclared identifier
client.cpp(6) : error C2146: syntax error : missing ';' before identifier
'ob'
client.cpp(6) : error C2065: 'ob' : undeclared identifier
client.cpp(7) : error C2227: left of '->CreateInstance' must point to
class/struct/union
type is ''unknown-type''
client.cpp(7) : error C3861: 'ob': identifier not found, even with
argument-dependent lookup
client.cpp(8) : error C2227: left of '->PrintString' must point to
class/struct/union
type is ''unknown-type''
client.cpp(8) : error C3861: 'ob': identifier not found, even with
argument-dependent lookup
 
S

Simon Smith

****** C# DLL ********

public void PrintString(string strName)

****** C Code *******

#import "ECSLink.tlb"



client.cpp
client.cpp(6) : error C2065: 'ECSInvokePtr' : undeclared identifier
client.cpp(6) : error C2146: syntax error : missing ';' before identifier
'ob'
client.cpp(6) : error C2065: 'ob' : undeclared identifier
client.cpp(7) : error C2227: left of '->CreateInstance' must point to
class/struct/union
type is ''unknown-type''
client.cpp(7) : error C3861: 'ob': identifier not found, even with
argument-dependent lookup
client.cpp(8) : error C2227: left of '->PrintString' must point to
class/struct/union
type is ''unknown-type''
client.cpp(8) : error C3861: 'ob': identifier not found, even with
argument-dependent lookup

I'm no C programmer, but you're calling PrintString with no parameters
and it's defined with a string parameter. That makes sense of some of the
error messages?


Simon Smith
simon dot s at ghytred dot com
www.ghytred.com/NewsLook - NNTP Client for Outlook
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top