473,806 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble converting C# class into COM

hi,

I want to convert a C# class into COM, so that I can use the class in C++.
The codes compile and link well. But when I run the program, I got a
exception.
Any comment is welcome. Thanks in advance.

Eric
----------------------------------------------------------------------
in C#, compile into a COM :

using System;
using System.Net;
using System.Net.Sock ets;
using System.Text;
using System.Collecti ons;

namespace SonicBase
{
public delegate int dProc(byte[] buf, int offset, int size);
public class MyClass : IMyClass
{

private dProc myProc = null;

bool StartServer(dPr oc dlgt)
{
myProc = dlgt;

byte[] buf = new byte[100];
int ret = myProc(buf, 0, 100);

return (ret > 0);
}

bool SonicBase.IMyCl ass.StartServer (dProc dlgt)
{
return false;
}

}

public interface IMyClass
{
bool StartServer(dPr oc dlgt);
}
}

--------------------------------------------------------------------------
in C++, use the COM :

// To use managed-code servers like the C# server,
// we have to import the common language runtime:
#import "mscorlib.t lb" raw_interfaces_ only

#import "EricBase.t lb" no_namespace named_guids

extern "C"
int ProcData(char* buf, int offset, int size)
{
return 0;
}

void CMainFrame::OnT est()
{
CoInitialize(NU LL);

IMyClass* icp = NULL;
HRESULT hr = CoCreateInstanc e(CLSID_MyClass ,
NULL, CLSCTX_INPROC_S ERVER,
IID_IMyClass, reinterpret_cas t<void**>(&icp) );
DWORD count=0;
AllocConsole();
HANDLE hOut = GetStdHandle(ST D_OUTPUT_HANDLE );
WriteConsole(hO ut, "a\n", 2, &count, NULL);

if(FAILED(hr))
{
AfxMessageBox(" fail create");
return;
}

try
{
_dProc* dlgt = (_dProc*)ProcDa ta;
icp->StartServer(dl gt);
}
catch(_com_erro r e)
{
CString strInfo = e.ErrorMessage( );
}

WriteConsole(hO ut, "b\n", 2, &count, NULL);

CoUninitialize( );
}
Nov 16 '05 #1
11 1992
Hmm... this is tricky stuff.
You can't pass a C function ptr and use it directly as a delegate pointer,
you have to pass it as a long (C/C++) and marshal this value as a
FuctionPtr.
Here's what you should do.

1. change you C# code..

public interface IMyClass
{
bool StartServer(dPr oc dlgt);
}
into:

public interface IMyClass
{
bool StartServer([MarshalAs(Unman agedType.Functi onPtr)]dProc dlgt);
}

2. Your C++ code:

icp->StartServer(dl gt);
into:
// reinterpret_cas t - You know what you are doing, don't you?
icp->StartServer(re interpret_cast< long>(dlgt));

Why do you implement an explicit interface for the method, there is no need
to do this just declare your interface methods as public. Or am I missing
something?

Willy.
"Eric" <wa**********@m sn.com> wrote in message
news:ub******** ******@TK2MSFTN GP15.phx.gbl...
hi,

I want to convert a C# class into COM, so that I can use the class in C++.
The codes compile and link well. But when I run the program, I got a
exception.
Any comment is welcome. Thanks in advance.

Eric
----------------------------------------------------------------------
in C#, compile into a COM :

using System;
using System.Net;
using System.Net.Sock ets;
using System.Text;
using System.Collecti ons;

namespace SonicBase
{
public delegate int dProc(byte[] buf, int offset, int size);
public class MyClass : IMyClass
{

private dProc myProc = null;

bool StartServer(dPr oc dlgt)
{
myProc = dlgt;

byte[] buf = new byte[100];
int ret = myProc(buf, 0, 100);

return (ret > 0);
}

bool SonicBase.IMyCl ass.StartServer (dProc dlgt)
{
return false;
}

}

public interface IMyClass
{
bool StartServer(dPr oc dlgt);
}
}

--------------------------------------------------------------------------
in C++, use the COM :

// To use managed-code servers like the C# server,
// we have to import the common language runtime:
#import "mscorlib.t lb" raw_interfaces_ only

#import "EricBase.t lb" no_namespace named_guids

extern "C"
int ProcData(char* buf, int offset, int size)
{
return 0;
}

void CMainFrame::OnT est()
{
CoInitialize(NU LL);

IMyClass* icp = NULL;
HRESULT hr = CoCreateInstanc e(CLSID_MyClass ,
NULL, CLSCTX_INPROC_S ERVER,
IID_IMyClass, reinterpret_cas t<void**>(&icp) );
DWORD count=0;
AllocConsole();
HANDLE hOut = GetStdHandle(ST D_OUTPUT_HANDLE );
WriteConsole(hO ut, "a\n", 2, &count, NULL);

if(FAILED(hr))
{
AfxMessageBox(" fail create");
return;
}

try
{
_dProc* dlgt = (_dProc*)ProcDa ta;
icp->StartServer(dl gt);
}
catch(_com_erro r e)
{
CString strInfo = e.ErrorMessage( );
}

WriteConsole(hO ut, "b\n", 2, &count, NULL);

CoUninitialize( );
}

Nov 16 '05 #2
Check out the information at:
http://msdn.microsoft.com/library/de...nentstocom.asp

Also checkout the interop news group:
microsoft.publi c.dotnet.framew ork.interop
"Eric" <wa**********@m sn.com> wrote in message
news:ub******** ******@TK2MSFTN GP15.phx.gbl...
hi,

I want to convert a C# class into COM, so that I can use the class in C++.
The codes compile and link well. But when I run the program, I got a
exception.
Any comment is welcome. Thanks in advance.

Eric
----------------------------------------------------------------------
in C#, compile into a COM :

using System;
using System.Net;
using System.Net.Sock ets;
using System.Text;
using System.Collecti ons;

namespace SonicBase
{
public delegate int dProc(byte[] buf, int offset, int size);
public class MyClass : IMyClass
{

private dProc myProc = null;

bool StartServer(dPr oc dlgt)
{
myProc = dlgt;

byte[] buf = new byte[100];
int ret = myProc(buf, 0, 100);

return (ret > 0);
}

bool SonicBase.IMyCl ass.StartServer (dProc dlgt)
{
return false;
}

}

public interface IMyClass
{
bool StartServer(dPr oc dlgt);
}
}

--------------------------------------------------------------------------
in C++, use the COM :

// To use managed-code servers like the C# server,
// we have to import the common language runtime:
#import "mscorlib.t lb" raw_interfaces_ only

#import "EricBase.t lb" no_namespace named_guids

extern "C"
int ProcData(char* buf, int offset, int size)
{
return 0;
}

void CMainFrame::OnT est()
{
CoInitialize(NU LL);

IMyClass* icp = NULL;
HRESULT hr = CoCreateInstanc e(CLSID_MyClass ,
NULL, CLSCTX_INPROC_S ERVER,
IID_IMyClass, reinterpret_cas t<void**>(&icp) );
DWORD count=0;
AllocConsole();
HANDLE hOut = GetStdHandle(ST D_OUTPUT_HANDLE );
WriteConsole(hO ut, "a\n", 2, &count, NULL);

if(FAILED(hr))
{
AfxMessageBox(" fail create");
return;
}

try
{
_dProc* dlgt = (_dProc*)ProcDa ta;
icp->StartServer(dl gt);
}
catch(_com_erro r e)
{
CString strInfo = e.ErrorMessage( );
}

WriteConsole(hO ut, "b\n", 2, &count, NULL);

CoUninitialize( );
}

Nov 16 '05 #3

Hi, Willy,

After modifying the code, I got another exception saying that "invalid
agument", I guessed there would be some mismatch between delegate dProc and
functionPtr ProcData, but I don't know what's wrong.

I looked into the MSDN, it gaves only the samples using explicit
interface. Would you please give me a sample without an explicit interface?
Using interface to export a C# class into COM, is troublesome. It would be a
great pleasure not using the explicit interface here.

Thanks,
Eric
"Willy Denoyette [MVP]" <wi************ *@pandora.be> дÈëÓʼþ
news:ux******** ******@TK2MSFTN GP14.phx.gbl...
Hmm... this is tricky stuff.
You can't pass a C function ptr and use it directly as a delegate pointer,
you have to pass it as a long (C/C++) and marshal this value as a
FuctionPtr.
Here's what you should do.

1. change you C# code..

public interface IMyClass
{
bool StartServer(dPr oc dlgt);
}
into:

public interface IMyClass
{
bool StartServer([MarshalAs(Unman agedType.Functi onPtr)]dProc dlgt);
}

2. Your C++ code:

icp->StartServer(dl gt);
into:
// reinterpret_cas t - You know what you are doing, don't you?
icp->StartServer(re interpret_cast< long>(dlgt));

Why do you implement an explicit interface for the method, there is no need to do this just declare your interface methods as public. Or am I missing
something?

Willy.
"Eric" <wa**********@m sn.com> wrote in message
news:ub******** ******@TK2MSFTN GP15.phx.gbl...
hi,

I want to convert a C# class into COM, so that I can use the class in C++. The codes compile and link well. But when I run the program, I got a
exception.
Any comment is welcome. Thanks in advance.

Eric
----------------------------------------------------------------------
in C#, compile into a COM :

using System;
using System.Net;
using System.Net.Sock ets;
using System.Text;
using System.Collecti ons;

namespace SonicBase
{
public delegate int dProc(byte[] buf, int offset, int size);
public class MyClass : IMyClass
{

private dProc myProc = null;

bool StartServer(dPr oc dlgt)
{
myProc = dlgt;

byte[] buf = new byte[100];
int ret = myProc(buf, 0, 100);

return (ret > 0);
}

bool SonicBase.IMyCl ass.StartServer (dProc dlgt)
{
return false;
}

}

public interface IMyClass
{
bool StartServer(dPr oc dlgt);
}
}


--------------------------------------------------------------------------
in C++, use the COM :

// To use managed-code servers like the C# server,
// we have to import the common language runtime:
#import "mscorlib.t lb" raw_interfaces_ only

#import "EricBase.t lb" no_namespace named_guids

extern "C"
int ProcData(char* buf, int offset, int size)
{
return 0;
}

void CMainFrame::OnT est()
{
CoInitialize(NU LL);

IMyClass* icp = NULL;
HRESULT hr = CoCreateInstanc e(CLSID_MyClass ,
NULL, CLSCTX_INPROC_S ERVER,
IID_IMyClass, reinterpret_cas t<void**>(&icp) );
DWORD count=0;
AllocConsole();
HANDLE hOut = GetStdHandle(ST D_OUTPUT_HANDLE );
WriteConsole(hO ut, "a\n", 2, &count, NULL);

if(FAILED(hr))
{
AfxMessageBox(" fail create");
return;
}

try
{
_dProc* dlgt = (_dProc*)ProcDa ta;
icp->StartServer(dl gt);
}
catch(_com_erro r e)
{
CString strInfo = e.ErrorMessage( );
}

WriteConsole(hO ut, "b\n", 2, &count, NULL);

CoUninitialize( );
}


Nov 16 '05 #4

I read the articles from the link, but i can't get what i need.

thank you any way.
"Howard Swope" <howardsnewsATs pitzincDOTcom> дÈëÓʼþ
news:ug******** ******@TK2MSFTN GP11.phx.gbl...
Check out the information at:
http://msdn.microsoft.com/library/de...nentstocom.asp
Also checkout the interop news group:
microsoft.publi c.dotnet.framew ork.interop
"Eric" <wa**********@m sn.com> wrote in message
news:ub******** ******@TK2MSFTN GP15.phx.gbl...
hi,

I want to convert a C# class into COM, so that I can use the class in C++. The codes compile and link well. But when I run the program, I got a
exception.
Any comment is welcome. Thanks in advance.

Eric
----------------------------------------------------------------------
in C#, compile into a COM :

using System;
using System.Net;
using System.Net.Sock ets;
using System.Text;
using System.Collecti ons;

namespace SonicBase
{
public delegate int dProc(byte[] buf, int offset, int size);
public class MyClass : IMyClass
{

private dProc myProc = null;

bool StartServer(dPr oc dlgt)
{
myProc = dlgt;

byte[] buf = new byte[100];
int ret = myProc(buf, 0, 100);

return (ret > 0);
}

bool SonicBase.IMyCl ass.StartServer (dProc dlgt)
{
return false;
}

}

public interface IMyClass
{
bool StartServer(dPr oc dlgt);
}
}


--------------------------------------------------------------------------
in C++, use the COM :

// To use managed-code servers like the C# server,
// we have to import the common language runtime:
#import "mscorlib.t lb" raw_interfaces_ only

#import "EricBase.t lb" no_namespace named_guids

extern "C"
int ProcData(char* buf, int offset, int size)
{
return 0;
}

void CMainFrame::OnT est()
{
CoInitialize(NU LL);

IMyClass* icp = NULL;
HRESULT hr = CoCreateInstanc e(CLSID_MyClass ,
NULL, CLSCTX_INPROC_S ERVER,
IID_IMyClass, reinterpret_cas t<void**>(&icp) );
DWORD count=0;
AllocConsole();
HANDLE hOut = GetStdHandle(ST D_OUTPUT_HANDLE );
WriteConsole(hO ut, "a\n", 2, &count, NULL);

if(FAILED(hr))
{
AfxMessageBox(" fail create");
return;
}

try
{
_dProc* dlgt = (_dProc*)ProcDa ta;
icp->StartServer(dl gt);
}
catch(_com_erro r e)
{
CString strInfo = e.ErrorMessage( );
}

WriteConsole(hO ut, "b\n", 2, &count, NULL);

CoUninitialize( );
}


Nov 16 '05 #5

I knows how to export C# class into COM without an explicit interface now.
like following:

namespace EricBase
{
[ClassInterface( ClassInterfaceT ype.AutoDual)] //strange syntax, but it's
the key
[Guid("64074EFB-17F6-4eb8-BC35-116A4FC950DB")]
public class Test
{
public void FuncA()
{
System.Console. WriteLine("in the COM");
}
}
}
the exception says "invalid agument" is still not solved.


"Eric" <wa**********@m sn.com> дÈëÓʼþ
news:eq******** ******@TK2MSFTN GP14.phx.gbl...

Hi, Willy,

After modifying the code, I got another exception saying that "invalid
agument", I guessed there would be some mismatch between delegate dProc and functionPtr ProcData, but I don't know what's wrong.

I looked into the MSDN, it gaves only the samples using explicit
interface. Would you please give me a sample without an explicit interface? Using interface to export a C# class into COM, is troublesome. It would be a great pleasure not using the explicit interface here.

Thanks,
Eric
"Willy Denoyette [MVP]" <wi************ *@pandora.be> дÈëÓʼþ
news:ux******** ******@TK2MSFTN GP14.phx.gbl...
Hmm... this is tricky stuff.
You can't pass a C function ptr and use it directly as a delegate pointer,
you have to pass it as a long (C/C++) and marshal this value as a
FuctionPtr.
Here's what you should do.

1. change you C# code..

public interface IMyClass
{
bool StartServer(dPr oc dlgt);
}
into:

public interface IMyClass
{
bool StartServer([MarshalAs(Unman agedType.Functi onPtr)]dProc dlgt);
}

2. Your C++ code:

icp->StartServer(dl gt);
into:
// reinterpret_cas t - You know what you are doing, don't you?
icp->StartServer(re interpret_cast< long>(dlgt));

Why do you implement an explicit interface for the method, there is no

need
to do this just declare your interface methods as public. Or am I missing something?

Willy.
"Eric" <wa**********@m sn.com> wrote in message
news:ub******** ******@TK2MSFTN GP15.phx.gbl...
hi,

I want to convert a C# class into COM, so that I can use the class in

C++. The codes compile and link well. But when I run the program, I got a
exception.
Any comment is welcome. Thanks in advance.

Eric
----------------------------------------------------------------------
in C#, compile into a COM :

using System;
using System.Net;
using System.Net.Sock ets;
using System.Text;
using System.Collecti ons;

namespace SonicBase
{
public delegate int dProc(byte[] buf, int offset, int size);
public class MyClass : IMyClass
{

private dProc myProc = null;

bool StartServer(dPr oc dlgt)
{
myProc = dlgt;

byte[] buf = new byte[100];
int ret = myProc(buf, 0, 100);

return (ret > 0);
}

bool SonicBase.IMyCl ass.StartServer (dProc dlgt)
{
return false;
}

}

public interface IMyClass
{
bool StartServer(dPr oc dlgt);
}
}


--------------------------------------------------------------------------
in C++, use the COM :

// To use managed-code servers like the C# server,
// we have to import the common language runtime:
#import "mscorlib.t lb" raw_interfaces_ only

#import "EricBase.t lb" no_namespace named_guids

extern "C"
int ProcData(char* buf, int offset, int size)
{
return 0;
}

void CMainFrame::OnT est()
{
CoInitialize(NU LL);

IMyClass* icp = NULL;
HRESULT hr = CoCreateInstanc e(CLSID_MyClass ,
NULL, CLSCTX_INPROC_S ERVER,
IID_IMyClass, reinterpret_cas t<void**>(&icp) );
DWORD count=0;
AllocConsole();
HANDLE hOut = GetStdHandle(ST D_OUTPUT_HANDLE );
WriteConsole(hO ut, "a\n", 2, &count, NULL);

if(FAILED(hr))
{
AfxMessageBox(" fail create");
return;
}

try
{
_dProc* dlgt = (_dProc*)ProcDa ta;
icp->StartServer(dl gt);
}
catch(_com_erro r e)
{
CString strInfo = e.ErrorMessage( );
}

WriteConsole(hO ut, "b\n", 2, &count, NULL);

CoUninitialize( );
}



Nov 16 '05 #6

"Eric" <wa**********@m sn.com> wrote in message
news:ed******** *****@TK2MSFTNG P11.phx.gbl...

I knows how to export C# class into COM without an explicit interface now.
like following:

namespace EricBase
{
[ClassInterface( ClassInterfaceT ype.AutoDual)] //strange syntax, but
it's
the key
[Guid("64074EFB-17F6-4eb8-BC35-116A4FC950DB")]
public class Test
{
public void FuncA()
{
System.Console. WriteLine("in the COM");
}
}
}
the exception says "invalid agument" is still not solved.


No, your problem was that your interface method was not public. The reason
it 'works' now has nothing to do with the ClassInterface attribute.
Not that it's much better to indicate the types and UUID's of your COM
interfaces explicitely.

Not sure where/when the exception is thrown on you. Still I'm not clear on
what you are trying here, basically you are using COM interop in one sense
(cpp -> cs) and PInvoke interop in the other (cs -> cpp), I hope you have
some real reason to do this.
But, next is a sample based on your original posting, maybe this will give
you some clue.

1. CS COM - server:
// server.cs
using System;
using System.Runtime. InteropServices ;
namespace Whatever
{

public delegate int dProc(byte[] buf, int offset, int size);
// class interface (coclass)
[ClassInterface( ClassInterfaceT ype.None)]
[Guid("fa7e5cdd-766f-4541-9b9b-aee0cdde5c74")]
[ProgId("Test.My Class")]
public class MyClass :IMyClass
{
private dProc myProc = null;

public bool StartServer(dPr oc dlgt)
{
int ret = 0;
myProc = dlgt;
byte[] buf = new byte[] {65, 66, 67, 68, 69, 70, 00}; // drop some bytes
in the buffer
ret = myProc(buf, 0, buf.Length);
return (ret > 0);
}
}
// interface
[InterfaceType(C omInterfaceType .InterfaceIsDua l)]
[Guid("29853bbf-1838-49fe-8a70-eb262f24ee56")]
public interface IMyClass
{
bool StartServer([MarshalAs(Unman agedType.Functi onPtr)]dProc dlgt);
}
}

2. CPP file - client:
///////////////////////////////////
// C++ program
///////////////////////////////////
// cl /EHsc inprocclient.cp p

#define _WIN32_WINNT 0x0501
#include <objbase.h>
#include <iostream>
#import "server.tlb " no_namespace named_guids

// Callback function
extern "C"
int __stdcall ProcData(char* buf, int offset, int size)
{
std::cout << buf << "\toffset: " << offset << "\tsize: " << size <<
std::endl;
return 0;
}

int main ()
{
::CoInitialize( NULL);
// Create an instance of the COM object using smart ptr
IMyClassPtr pPtr(__uuidof(M yClass));
_dProc* dlgt = (_dProc*)ProcDa ta;
//pPtr->Dummy();
// Call method passing a function pointer as a long
// the interop layer must marshal this long to a valid function pointer
used as delegate pointer
// See CS file
pPtr->StartServer(re interpret_cast< long>(dlgt));
// uninitialize COM
::CoUninitializ e();
}

To build from the commandline, issue following commands (Ignore warning in
3):

regasm /unregister /tlb server.dll
csc /t:library server.cs
regasm /codebase /tlb server.dll
cl /EHsc inprocclient.cp p

run the client.

Willy.
Nov 16 '05 #7
Thank you for your warmhearted reply.
I tried your code, an exception was thrown out at
"pPtr->StartServer(re interpret_cast< long>(dlgt));" saying "invalid agument"
I stepped into the code, found that "raw_StartServe r(dlgt, &_result);"
returns "E_INVALIDA RG" and cause _com_issue_erro rex() to throw out an
exception. Why raw_StartServer () returns "E_INVALIDA RG" here ?

"Willy Denoyette [MVP]" <wi************ *@pandora.be> дÈëÓʼþ
news:OP******** *****@TK2MSFTNG P11.phx.gbl...

"Eric" <wa**********@m sn.com> wrote in message
news:ed******** *****@TK2MSFTNG P11.phx.gbl...

I knows how to export C# class into COM without an explicit interface now. like following:

namespace EricBase
{
[ClassInterface( ClassInterfaceT ype.AutoDual)] //strange syntax, but
it's
the key
[Guid("64074EFB-17F6-4eb8-BC35-116A4FC950DB")]
public class Test
{
public void FuncA()
{
System.Console. WriteLine("in the COM");
}
}
}
the exception says "invalid agument" is still not solved.

No, your problem was that your interface method was not public. The reason
it 'works' now has nothing to do with the ClassInterface attribute.
Not that it's much better to indicate the types and UUID's of your COM
interfaces explicitely.

Not sure where/when the exception is thrown on you. Still I'm not clear on
what you are trying here, basically you are using COM interop in one sense
(cpp -> cs) and PInvoke interop in the other (cs -> cpp), I hope you have
some real reason to do this.
But, next is a sample based on your original posting, maybe this will give
you some clue.

1. CS COM - server:
// server.cs
using System;
using System.Runtime. InteropServices ;
namespace Whatever
{

public delegate int dProc(byte[] buf, int offset, int size);
// class interface (coclass)
[ClassInterface( ClassInterfaceT ype.None)]
[Guid("fa7e5cdd-766f-4541-9b9b-aee0cdde5c74")]
[ProgId("Test.My Class")]
public class MyClass :IMyClass
{
private dProc myProc = null;

public bool StartServer(dPr oc dlgt)
{
int ret = 0;
myProc = dlgt;
byte[] buf = new byte[] {65, 66, 67, 68, 69, 70, 00}; // drop some

bytes in the buffer
ret = myProc(buf, 0, buf.Length);
return (ret > 0);
}
}
// interface
[InterfaceType(C omInterfaceType .InterfaceIsDua l)]
[Guid("29853bbf-1838-49fe-8a70-eb262f24ee56")]
public interface IMyClass
{
bool StartServer([MarshalAs(Unman agedType.Functi onPtr)]dProc dlgt);
}
}

2. CPP file - client:
///////////////////////////////////
// C++ program
///////////////////////////////////
// cl /EHsc inprocclient.cp p

#define _WIN32_WINNT 0x0501
#include <objbase.h>
#include <iostream>
#import "server.tlb " no_namespace named_guids

// Callback function
extern "C"
int __stdcall ProcData(char* buf, int offset, int size)
{
std::cout << buf << "\toffset: " << offset << "\tsize: " << size <<
std::endl;
return 0;
}

int main ()
{
::CoInitialize( NULL);
// Create an instance of the COM object using smart ptr
IMyClassPtr pPtr(__uuidof(M yClass));
_dProc* dlgt = (_dProc*)ProcDa ta;
//pPtr->Dummy();
// Call method passing a function pointer as a long
// the interop layer must marshal this long to a valid function pointer
used as delegate pointer
// See CS file
pPtr->StartServer(re interpret_cast< long>(dlgt));
// uninitialize COM
::CoUninitializ e();
}

To build from the commandline, issue following commands (Ignore warning in
3):

regasm /unregister /tlb server.dll
csc /t:library server.cs
regasm /codebase /tlb server.dll
cl /EHsc inprocclient.cp p

run the client.

Willy.

Nov 16 '05 #8

"Eric" <wa**********@m sn.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Thank you for your warmhearted reply.
I tried your code, an exception was thrown out at
"pPtr->StartServer(re interpret_cast< long>(dlgt));" saying "invalid
agument"
I stepped into the code, found that "raw_StartServe r(dlgt, &_result);"
returns "E_INVALIDA RG" and cause _com_issue_erro rex() to throw out an
exception. Why raw_StartServer () returns "E_INVALIDA RG" here ?


The same code dumps :

ABCDEF offset: 0 size: 7

to the console when run on Framework v1.1.4322 (v1.1 SP1).
I'm using the latest C++ compiler ( Version 14.00.40904) to compile the cpp,
not sure what you are using. Did you inspect the tli and tlh files?
Are you sure you registered the tlb (regasm /tlb ...)?

Willy.

Nov 16 '05 #9
hi Willy,

I do the work with VirsualStudio20 03, same version as you.

Look into the following link:
http://www.dotnetinterop.com/feature...aspx?q=Whidbey

It says: in dotNET v2.0 "The runtime now supports marshaling of function
pointers to delegates. The reverse - delegate to function pointer - has been
possible since version one. "

Isn't it means we can't marshal function pointers to delegates currently now
?

Am I misunderstand something ?

Regards,
Eric

"Willy Denoyette [MVP]" <wi************ *@pandora.be> дÈëÓʼþ
news:ux******** ******@TK2MSFTN GP14.phx.gbl...

"Eric" <wa**********@m sn.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Thank you for your warmhearted reply.
I tried your code, an exception was thrown out at
"pPtr->StartServer(re interpret_cast< long>(dlgt));" saying "invalid
agument"
I stepped into the code, found that "raw_StartServe r(dlgt, &_result);"
returns "E_INVALIDA RG" and cause _com_issue_erro rex() to throw out an
exception. Why raw_StartServer () returns "E_INVALIDA RG" here ?

The same code dumps :

ABCDEF offset: 0 size: 7

to the console when run on Framework v1.1.4322 (v1.1 SP1).
I'm using the latest C++ compiler ( Version 14.00.40904) to compile the

cpp, not sure what you are using. Did you inspect the tli and tlh files?
Are you sure you registered the tlb (regasm /tlb ...)?

Willy.


Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
1342
by: Exits Funnel | last post by:
Hello, I've been tasked with porting some C++ code from Windows to Linux. The following excerpt is giving me trouble: //BEGIN CODE #include <string> class TempTestBase_t {
5
2529
by: Robert | last post by:
I have a series of web applications (configured as separate applications) on a server. There is a main application at the root and then several virtual directories that are independant applications. I am testing an upgrade of all of the sites and have converted the main root site...although not necessarily fixed any issues. I move on instead and converted one of the virtual roots that is a seperate
1
1301
by: Friso Wiskerke | last post by:
Hi All, We've got an VS.2003 ASPNET (VB) webproject which we would like to convert to VS.2005 so that we can make use of the Master Page feature. Converting the initial pages to 2005 is not such a problem (some minor errors) but we run into trouble when we're trying to insert a converted page into a master page content-placeholder. The original page has some Javascript in it which ofcourse references to controls in a form in the page....
9
2581
by: Terry | last post by:
I am converting (attempting) some vb6 code that makes vast use of interfaces. One of the major uses is to be able to split out Read-only access to an obect. Let me give you a simple (contrived) example: In Project RoObjDefs: RoPerson.cls file: Public Property Get FirstName() as String Public Property Get LastName() as String <end of file RoPerson.cls> RoPersons.cls file Public Function Count() as Integer
10
8162
by: Hendri Adriaens | last post by:
Hi, I'm trying to automate the creation of an excel file via COM. I copied my code below. I read many articles about how to release the COM objects that I create. The code below runs just fine and excel is closed. But there are some commented lines: //xlSeries.XValues = xlWs.get_Range("B2", "B4"); // makes com objects, but which...
3
1926
by: Michellevt | last post by:
Hi I am working on a project (for college) and wondered if anyone can help me with my problem. In the project we are not allowed to make use of any "style" attributes but "class" attributes instead. The following is the java script that i am using and i am having trouble in using a class instead of a style tag because simply replacing the style=\"position:absolute;\" tag with class=\"posiAbs\" where in the external css ".posiAbs...
6
2185
by: jnonly | last post by:
Hello, I recently converted projects from VS7.1 (2003) to VS9.0 (2008) and am getting the following error on some subroutine declarations: error BC30284: sub 'SomeSub' cannot be declared 'Overrides' because it does not override a sub in a base class. The subs on which this occurs have parameters of a type that comes from an external COM library. I have added references to the library
5
2442
matheussousuke
by: matheussousuke | last post by:
Hi guys, good morning. I've just get this script for converting mysql tables from wordpress, and I want to use it in my server, but no with wordpress, with oscommerce, a friend of mine told me a few things I should do for make it working, but less than a rookie in PHP, began studying it now ¬¬", and sure I dont know how to use command line yet, she told me something about using command line along with FTP ascii table, I'm lost, couldn't do...
5
13389
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the website URL before the image URL.
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10617
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10370
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4328
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3849
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.