473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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.Sockets;
using System.Text;
using System.Collections;

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

private dProc myProc = null;

bool StartServer(dProc dlgt)
{
myProc = dlgt;

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

return (ret > 0);
}

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

}

public interface IMyClass
{
bool StartServer(dProc 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.tlb" raw_interfaces_only

#import "EricBase.tlb" no_namespace named_guids

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

void CMainFrame::OnTest()
{
CoInitialize(NULL);

IMyClass* icp = NULL;
HRESULT hr = CoCreateInstance(CLSID_MyClass,
NULL, CLSCTX_INPROC_SERVER,
IID_IMyClass, reinterpret_cast<void**>(&icp));
DWORD count=0;
AllocConsole();
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
WriteConsole(hOut, "a\n", 2, &count, NULL);

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

try
{
_dProc* dlgt = (_dProc*)ProcData;
icp->StartServer(dlgt);
}
catch(_com_error e)
{
CString strInfo = e.ErrorMessage();
}

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

CoUninitialize();
}
Nov 16 '05 #1
11 1960
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(dProc dlgt);
}
into:

public interface IMyClass
{
bool StartServer([MarshalAs(UnmanagedType.FunctionPtr)]dProc dlgt);
}

2. Your C++ code:

icp->StartServer(dlgt);
into:
// reinterpret_cast - You know what you are doing, don't you?
icp->StartServer(reinterpret_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**********@msn.com> wrote in message
news:ub**************@TK2MSFTNGP15.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.Sockets;
using System.Text;
using System.Collections;

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

private dProc myProc = null;

bool StartServer(dProc dlgt)
{
myProc = dlgt;

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

return (ret > 0);
}

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

}

public interface IMyClass
{
bool StartServer(dProc 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.tlb" raw_interfaces_only

#import "EricBase.tlb" no_namespace named_guids

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

void CMainFrame::OnTest()
{
CoInitialize(NULL);

IMyClass* icp = NULL;
HRESULT hr = CoCreateInstance(CLSID_MyClass,
NULL, CLSCTX_INPROC_SERVER,
IID_IMyClass, reinterpret_cast<void**>(&icp));
DWORD count=0;
AllocConsole();
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
WriteConsole(hOut, "a\n", 2, &count, NULL);

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

try
{
_dProc* dlgt = (_dProc*)ProcData;
icp->StartServer(dlgt);
}
catch(_com_error e)
{
CString strInfo = e.ErrorMessage();
}

WriteConsole(hOut, "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.public.dotnet.framework.interop
"Eric" <wa**********@msn.com> wrote in message
news:ub**************@TK2MSFTNGP15.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.Sockets;
using System.Text;
using System.Collections;

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

private dProc myProc = null;

bool StartServer(dProc dlgt)
{
myProc = dlgt;

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

return (ret > 0);
}

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

}

public interface IMyClass
{
bool StartServer(dProc 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.tlb" raw_interfaces_only

#import "EricBase.tlb" no_namespace named_guids

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

void CMainFrame::OnTest()
{
CoInitialize(NULL);

IMyClass* icp = NULL;
HRESULT hr = CoCreateInstance(CLSID_MyClass,
NULL, CLSCTX_INPROC_SERVER,
IID_IMyClass, reinterpret_cast<void**>(&icp));
DWORD count=0;
AllocConsole();
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
WriteConsole(hOut, "a\n", 2, &count, NULL);

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

try
{
_dProc* dlgt = (_dProc*)ProcData;
icp->StartServer(dlgt);
}
catch(_com_error e)
{
CString strInfo = e.ErrorMessage();
}

WriteConsole(hOut, "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**************@TK2MSFTNGP14.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(dProc dlgt);
}
into:

public interface IMyClass
{
bool StartServer([MarshalAs(UnmanagedType.FunctionPtr)]dProc dlgt);
}

2. Your C++ code:

icp->StartServer(dlgt);
into:
// reinterpret_cast - You know what you are doing, don't you?
icp->StartServer(reinterpret_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**********@msn.com> wrote in message
news:ub**************@TK2MSFTNGP15.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.Sockets;
using System.Text;
using System.Collections;

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

private dProc myProc = null;

bool StartServer(dProc dlgt)
{
myProc = dlgt;

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

return (ret > 0);
}

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

}

public interface IMyClass
{
bool StartServer(dProc 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.tlb" raw_interfaces_only

#import "EricBase.tlb" no_namespace named_guids

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

void CMainFrame::OnTest()
{
CoInitialize(NULL);

IMyClass* icp = NULL;
HRESULT hr = CoCreateInstance(CLSID_MyClass,
NULL, CLSCTX_INPROC_SERVER,
IID_IMyClass, reinterpret_cast<void**>(&icp));
DWORD count=0;
AllocConsole();
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
WriteConsole(hOut, "a\n", 2, &count, NULL);

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

try
{
_dProc* dlgt = (_dProc*)ProcData;
icp->StartServer(dlgt);
}
catch(_com_error e)
{
CString strInfo = e.ErrorMessage();
}

WriteConsole(hOut, "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" <howardsnewsATspitzincDOTcom> дÈëÓʼþ
news:ug**************@TK2MSFTNGP11.phx.gbl...
Check out the information at:
http://msdn.microsoft.com/library/de...nentstocom.asp
Also checkout the interop news group:
microsoft.public.dotnet.framework.interop
"Eric" <wa**********@msn.com> wrote in message
news:ub**************@TK2MSFTNGP15.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.Sockets;
using System.Text;
using System.Collections;

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

private dProc myProc = null;

bool StartServer(dProc dlgt)
{
myProc = dlgt;

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

return (ret > 0);
}

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

}

public interface IMyClass
{
bool StartServer(dProc 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.tlb" raw_interfaces_only

#import "EricBase.tlb" no_namespace named_guids

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

void CMainFrame::OnTest()
{
CoInitialize(NULL);

IMyClass* icp = NULL;
HRESULT hr = CoCreateInstance(CLSID_MyClass,
NULL, CLSCTX_INPROC_SERVER,
IID_IMyClass, reinterpret_cast<void**>(&icp));
DWORD count=0;
AllocConsole();
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
WriteConsole(hOut, "a\n", 2, &count, NULL);

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

try
{
_dProc* dlgt = (_dProc*)ProcData;
icp->StartServer(dlgt);
}
catch(_com_error e)
{
CString strInfo = e.ErrorMessage();
}

WriteConsole(hOut, "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(ClassInterfaceType.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**********@msn.com> дÈëÓʼþ
news:eq**************@TK2MSFTNGP14.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**************@TK2MSFTNGP14.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(dProc dlgt);
}
into:

public interface IMyClass
{
bool StartServer([MarshalAs(UnmanagedType.FunctionPtr)]dProc dlgt);
}

2. Your C++ code:

icp->StartServer(dlgt);
into:
// reinterpret_cast - You know what you are doing, don't you?
icp->StartServer(reinterpret_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**********@msn.com> wrote in message
news:ub**************@TK2MSFTNGP15.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.Sockets;
using System.Text;
using System.Collections;

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

private dProc myProc = null;

bool StartServer(dProc dlgt)
{
myProc = dlgt;

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

return (ret > 0);
}

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

}

public interface IMyClass
{
bool StartServer(dProc 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.tlb" raw_interfaces_only

#import "EricBase.tlb" no_namespace named_guids

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

void CMainFrame::OnTest()
{
CoInitialize(NULL);

IMyClass* icp = NULL;
HRESULT hr = CoCreateInstance(CLSID_MyClass,
NULL, CLSCTX_INPROC_SERVER,
IID_IMyClass, reinterpret_cast<void**>(&icp));
DWORD count=0;
AllocConsole();
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
WriteConsole(hOut, "a\n", 2, &count, NULL);

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

try
{
_dProc* dlgt = (_dProc*)ProcData;
icp->StartServer(dlgt);
}
catch(_com_error e)
{
CString strInfo = e.ErrorMessage();
}

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

CoUninitialize();
}



Nov 16 '05 #6

"Eric" <wa**********@msn.com> wrote in message
news:ed*************@TK2MSFTNGP11.phx.gbl...

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

namespace EricBase
{
[ClassInterface(ClassInterfaceType.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(ClassInterfaceType.None)]
[Guid("fa7e5cdd-766f-4541-9b9b-aee0cdde5c74")]
[ProgId("Test.MyClass")]
public class MyClass :IMyClass
{
private dProc myProc = null;

public bool StartServer(dProc 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(ComInterfaceType.InterfaceIsDual)]
[Guid("29853bbf-1838-49fe-8a70-eb262f24ee56")]
public interface IMyClass
{
bool StartServer([MarshalAs(UnmanagedType.FunctionPtr)]dProc dlgt);
}
}

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

#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(MyClass));
_dProc* dlgt = (_dProc*)ProcData;
//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(reinterpret_cast<long>(dlgt));
// uninitialize COM
::CoUninitialize();
}

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.cpp

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(reinterpret_cast<long>(dlgt));" saying "invalid agument"
I stepped into the code, found that "raw_StartServer(dlgt, &_result);"
returns "E_INVALIDARG" and cause _com_issue_errorex() to throw out an
exception. Why raw_StartServer() returns "E_INVALIDARG" here ?

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

"Eric" <wa**********@msn.com> wrote in message
news:ed*************@TK2MSFTNGP11.phx.gbl...

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

namespace EricBase
{
[ClassInterface(ClassInterfaceType.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(ClassInterfaceType.None)]
[Guid("fa7e5cdd-766f-4541-9b9b-aee0cdde5c74")]
[ProgId("Test.MyClass")]
public class MyClass :IMyClass
{
private dProc myProc = null;

public bool StartServer(dProc 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(ComInterfaceType.InterfaceIsDual)]
[Guid("29853bbf-1838-49fe-8a70-eb262f24ee56")]
public interface IMyClass
{
bool StartServer([MarshalAs(UnmanagedType.FunctionPtr)]dProc dlgt);
}
}

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

#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(MyClass));
_dProc* dlgt = (_dProc*)ProcData;
//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(reinterpret_cast<long>(dlgt));
// uninitialize COM
::CoUninitialize();
}

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.cpp

run the client.

Willy.

Nov 16 '05 #8

"Eric" <wa**********@msn.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Thank you for your warmhearted reply.
I tried your code, an exception was thrown out at
"pPtr->StartServer(reinterpret_cast<long>(dlgt));" saying "invalid
agument"
I stepped into the code, found that "raw_StartServer(dlgt, &_result);"
returns "E_INVALIDARG" and cause _com_issue_errorex() to throw out an
exception. Why raw_StartServer() returns "E_INVALIDARG" 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 VirsualStudio2003, 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**************@TK2MSFTNGP14.phx.gbl...

"Eric" <wa**********@msn.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Thank you for your warmhearted reply.
I tried your code, an exception was thrown out at
"pPtr->StartServer(reinterpret_cast<long>(dlgt));" saying "invalid
agument"
I stepped into the code, found that "raw_StartServer(dlgt, &_result);"
returns "E_INVALIDARG" and cause _com_issue_errorex() to throw out an
exception. Why raw_StartServer() returns "E_INVALIDARG" 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
No, marshaling function pointers has nothing to do with this.
You problem is related to an argument that is flagged as invalid by the
interop layer (CCW).

If you say "same version as you", I think you are mistaken, I'm not using VS
at all.

I'm using C++ v14.00.40904 to compile the C++ file from the command line,
this is NOT the version you have!.
I'm using Csharp compiler 7.10.6001.4 from the command line.
I'm using regasm.exe v 1.1.4322.573 from the commandline, using /tlb and
/codebase options.
I'm running this code on CLR v1.1 SP1 (version 1.1.4222) without a problem
(note SP1!!).
So basically the only difference is the C++ compiler, but IMO this is a non
issue as it compiles to native code only.

Willy.

"Eric" <wa**********@msn.com> wrote in message
news:uT**************@TK2MSFTNGP11.phx.gbl...
hi Willy,

I do the work with VirsualStudio2003, 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**************@TK2MSFTNGP14.phx.gbl...

"Eric" <wa**********@msn.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> Thank you for your warmhearted reply.
> I tried your code, an exception was thrown out at
> "pPtr->StartServer(reinterpret_cast<long>(dlgt));" saying "invalid
> agument"
> I stepped into the code, found that "raw_StartServer(dlgt, &_result);"
> returns "E_INVALIDARG" and cause _com_issue_errorex() to throw out an
> exception. Why raw_StartServer() returns "E_INVALIDARG" 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 #11
Thank you for you explanation. but I'm still puzzled whether we can
marshaling function pointers or not? I cares about this.

As it for me, every thing worked well until i tried to marshal a function
pointer to delegate.

regards,
eric

"Willy Denoyette [MVP]" <wi*************@pandora.be> дÈëÓʼþ
news:%2****************@TK2MSFTNGP12.phx.gbl...
No, marshaling function pointers has nothing to do with this.
You problem is related to an argument that is flagged as invalid by the
interop layer (CCW).

If you say "same version as you", I think you are mistaken, I'm not using VS at all.

I'm using C++ v14.00.40904 to compile the C++ file from the command line,
this is NOT the version you have!.
I'm using Csharp compiler 7.10.6001.4 from the command line.
I'm using regasm.exe v 1.1.4322.573 from the commandline, using /tlb and
/codebase options.
I'm running this code on CLR v1.1 SP1 (version 1.1.4222) without a problem
(note SP1!!).
So basically the only difference is the C++ compiler, but IMO this is a non issue as it compiles to native code only.

Willy.

"Eric" <wa**********@msn.com> wrote in message
news:uT**************@TK2MSFTNGP11.phx.gbl...
hi Willy,

I do the work with VirsualStudio2003, 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**************@TK2MSFTNGP14.phx.gbl...

"Eric" <wa**********@msn.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> Thank you for your warmhearted reply.
> I tried your code, an exception was thrown out at
> "pPtr->StartServer(reinterpret_cast<long>(dlgt));" saying "invalid
> agument"
> I stepped into the code, found that "raw_StartServer(dlgt, &_result);" > returns "E_INVALIDARG" and cause _com_issue_errorex() to throw out an
> exception. Why raw_StartServer() returns "E_INVALIDARG" 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 #12

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

Similar topics

8
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
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...
1
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...
9
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)...
10
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...
3
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...
6
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...
5
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...
5
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.