interop delegate for COM
From: Eric (wangshaoquan_at_msn.com)
Date: 12/01/04
- Next message: Bonj: "RE: Debugging C# assembly called from C++"
- Previous message: Juan Ignacio Gelos: "Re: MprAdminInterfaceEnum"
- Next in thread: Mattias Sjögren: "Re: interop delegate for COM"
- Reply: Mattias Sjögren: "Re: interop delegate for COM"
- Reply: Howard Swope: "Re: interop delegate for COM"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 1 Dec 2004 17:04:04 +0800
hi,
I want to pass a function pointer to COM, so that COM can callback in some
situation.
/////////////////////////////////////
// C# compile into COM
using System;
using System.Runtime.InteropServices;
namespace Whatever
{
public delegate void dProc();
[ClassInterface(ClassInterfaceType.AutoDual)]
[Guid("6DAFA2C2-BE89-4af3-92CF-A278E81D9C2D")]
public class MyClass
{
public bool SetHandler([MarshalAs(UnmanagedType.FunctionPtr)]dProc dlgt)
{
System.Console.WriteLine("in the COM\n");
return true;
}
}
}
////////////////////////////////////////
// C++ use the COM
#define _WIN32_WINNT 0x0501
#include <objbase.h>
#include <iostream>
#import "d:\project\lev3test\mscorlib.tlb" raw_interfaces_only
#import "d:\project\lev3test\ericbase.tlb" no_namespace named_guids
extern "C"
void __stdcall ProcData()
{
return;
}
int main ()
{
::CoInitialize(NULL);
try
{
_MyClassPtr pPtr(__uuidof(MyClass));
int dlgt = reinterpret_cast<int>(ProcData);
pPtr->SetHandler(dlgt);
}
catch(_com_error e)
{
std::cout << e.ErrorMessage() << std::endl;
}
::CoUninitialize();
getchar();
return 0;
}
// source end
/////////////////
two projects compile and link well. but when i run the program, i got an
exception at "pPtr->SetHandler(dlgt)" saying "invalid agument".
What's wrong here?
Thanks in advance.
Regards,
Eric
- Next message: Bonj: "RE: Debugging C# assembly called from C++"
- Previous message: Juan Ignacio Gelos: "Re: MprAdminInterfaceEnum"
- Next in thread: Mattias Sjögren: "Re: interop delegate for COM"
- Reply: Mattias Sjögren: "Re: interop delegate for COM"
- Reply: Howard Swope: "Re: interop delegate for COM"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|