Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / December 2004

Tip: Looking for answers? Try searching our database.

interop delegate for COM

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Eric - 01 Dec 2004 09:03 GMT
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
Mattias Sj?gren - 01 Dec 2004 15:32 GMT
The runtime currently doesn't support marshaling a native function
pointer to a managed delegate, only the other way around.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Eric - 06 Dec 2004 00:27 GMT
Thank you for your comment.

Regards,
Eric

> The runtime currently doesn't support marshaling a native function
> pointer to a managed delegate, only the other way around.
>
> Mattias
Howard Swope - 03 Dec 2004 16:06 GMT
You could setup your managed code to be COM callable and then pass an
interface pointer to your COM object. The COM object could then call back on
a functioned defined by the interface.

> hi,
>
[quoted text clipped - 63 lines]
> Regards,
> Eric
Eric - 06 Dec 2004 00:27 GMT
Would you please give me a sample or a link, shows me how to do this ?
Thanks.

Regards,
Eric

> You could setup your managed code to be COM callable and then pass an
> interface pointer to your COM object. The COM object could then call back on
[quoted text clipped - 68 lines]
> > Regards,
> > Eric

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.