how to pass bstr to com+ that made by C#

L

lightdoll

hello everyone.

i have created a com+ made by C#.

The COM+ is singleton.
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[Guid("9b7384f1-7fd3-444f-acd9-0551ae878caf")]
public interface IOpenInterface
{
bool K_SetEventId(string strSourceId, string strEventId);
int test();
}

[JustInTimeActivation]
[ObjectPooling(Enabled = true, MinPoolSize = 1, MaxPoolSize = 1,
CreationTimeout = 5000)]
[Guid("6d1bcaf4-1d35-44c5-b7cb-7431550ee9c0")]
[ProgId("EasyEda.OpenInterface")]
[ComVisible(true)]
public sealed class IOpenComponent : ServicedComponent, IOpenInterface
{

public IOpenComponent() { }

public int test()
{
System.Diagnostics.Debugger.Break();
return 10;
}
public bool K_SetEventId(string strSourceId, string strEventId)
{
System.Diagnostics.Debugger.Break();
return CEdaInterface.edaInstance.K_SetEventId(strSourceId,
strEventId);
}
}

i called the test function from dll made by c++.

it's ok.

but i called the other function from dll made by c++.

but a error was happened.

CoInitialize(NULL);
HRESULT hr = CoCreateInstance(CLSID_IOpenComponent ,
NULL, CLSCTX_LOCAL_SERVER,
IID_IOpenInterface ,
reinterpret_cast<void**>(&gIOpenInterface));
if(FAILED(hr))
{
OutputDebugString("The Interface failed");
return FALSE;
}
printf("%d\n", gIOpenInterface->test());==> it's ok.
_bstr_t bstr = ::SysAllocString(L"TEST");
gIOpenInterface->K_SetEventId(bstr, bstr);==> The error was happened.

i tried to solve this problem many times..but i can't...

anyone help me solve this problem.

best regards.
 
W

Willy Denoyette [MVP]

lightdoll said:
hello everyone.

i have created a com+ made by C#.

The COM+ is singleton.
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[Guid("9b7384f1-7fd3-444f-acd9-0551ae878caf")]
public interface IOpenInterface
{
bool K_SetEventId(string strSourceId, string strEventId);
int test();
}

[JustInTimeActivation]
[ObjectPooling(Enabled = true, MinPoolSize = 1, MaxPoolSize = 1,
CreationTimeout = 5000)]
[Guid("6d1bcaf4-1d35-44c5-b7cb-7431550ee9c0")]
[ProgId("EasyEda.OpenInterface")]
[ComVisible(true)]
public sealed class IOpenComponent : ServicedComponent, IOpenInterface
{

public IOpenComponent() { }

public int test()
{
System.Diagnostics.Debugger.Break();
return 10;
}
public bool K_SetEventId(string strSourceId, string strEventId)
{
System.Diagnostics.Debugger.Break();
return CEdaInterface.edaInstance.K_SetEventId(strSourceId,
strEventId);
}
}

i called the test function from dll made by c++.

it's ok.

but i called the other function from dll made by c++.

but a error was happened.

CoInitialize(NULL);
HRESULT hr = CoCreateInstance(CLSID_IOpenComponent ,
NULL, CLSCTX_LOCAL_SERVER,
IID_IOpenInterface ,
reinterpret_cast<void**>(&gIOpenInterface));
if(FAILED(hr))
{
OutputDebugString("The Interface failed");
return FALSE;
}
printf("%d\n", gIOpenInterface->test());==> it's ok.
_bstr_t bstr = ::SysAllocString(L"TEST");
gIOpenInterface->K_SetEventId(bstr, bstr);==> The error was happened.


This should work, please post the error message.

Willy.

Note: this issue relates to C++, you might get better answers when posting
to the microsoft.public.vc.language group or to the interop
microsoft.public.dotnet.framework.interop NG.
 
L

lightdoll

Thank you for your reply.

return CEdaInterface.edaInstance.K_SetEventId(strSourceId,
strEventId);
==> i think a part of this has some problem.

because i don't anything in test(), but i called another dll from K_SetEventId

but i don't modify the code yet.

public int test()
{
System.Diagnostics.Debugger.Break();
return 10;
}
public bool K_SetEventId(string strSourceId, string strEventId)
{
System.Diagnostics.Debugger.Break();
return CEdaInterface.edaInstance.K_SetEventId(strSourceId,
strEventId);
}
 
W

Willy Denoyette [MVP]

lightdoll said:
Thank you for your reply.

return CEdaInterface.edaInstance.K_SetEventId(strSourceId,
strEventId);
==> i think a part of this has some problem.

But what's the problem, any error message?
You are connected to a singleton, why are you calling back into
K_SetEventId? What are you trying to achive here?


Willy.
 

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