Subject: RE: Migrating to Managed C++
Date: Mon, 21 Jul 2003 01:02:51 -0700
Lines: 182
Message-ID: <
[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
X-Newsreader: Microsoft CDO for Windows 2000
Thread-Index: AcNPXnt6k37Jpf0aRnmU1iLzSyocwQ==
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Newsgroups: microsoft.public.dotnet.languages.vc
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:26370
NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
X-Tomcat-NG: microsoft.public.dotnet.languages.vc
NativeClass exports the following two memebers:
int NativeClass::SetCallback(void (*)(int ,void*),void *)
int NativeClass::SetCallback(void (*)(UnmanagedClass2&
umc2, void* p),void *)
As you recall these members provide the interface for
registering to callbacks
// class NativeClass
// {
// ...
// BOOL SetCallback(CbFunc1*,void*);
// BOOL SetCallback(CbFunc2*,void*);
// ....
-----Original Message-----
Hi Shai,
Can you tell me what the NativeClass exports in the dll?
You may not directly access the unmanaged dll class
member function in
managed code, as you mentioned in the last post.(public
static extern BOOL
NativeClass::SetCallback(CallBack x, IntPtr y)
You may check what your dll exports by using the tool
depends to open the
dll file, the tool is included in VS.NET or VS6.
please get back to me and let me know whether this does
the job for you.
Best regards
Peter Huang
Microsoft Online Partner Support
Get Secure!
www.microsoft.com/security
This posting is provided ¡°as is¡± with no warranties and
confers no rights.
--------------------
Content-Class: urn:content-classes:message
From: "Shai Levi" <
[email protected]>
Sender: "Shai Levi" <
[email protected]>
References: <
[email protected]>
<
[email protected]>
Subject: RE: Migrating to Managed C++
Date: Thu, 17 Jul 2003 07:58:01 -0700
Lines: 113
Message-ID: <
[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcNMc9FpZxdJ4ecxSmWaEpWo76iNpA==
Newsgroups: microsoft.public.dotnet.languages.vc
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.languages.vc:26278
NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
X-Tomcat-NG: microsoft.public.dotnet.languages.vc
Hi Peter,
In your example (that also appears in Platform Invoke
article) the function that is imported is a c function
(no
this)
[DllImport("user32")]
public static extern int EnumWindows(CallBack x, int y);
I can't figure out how I can import a class method -
public static extern BOOL NativeClass::SetCallback
(CallBack x, IntPtr y); ?
this is not working.
(I remind you that I can't change the native dll code)
-----Original Message-----
Hi Shai,
I think you can exports your member function as a
common
CALLBACK function.
Then you can import it in the managed code. Here is a
demo on how to invoke
API requiring Callback function.
using System;
using System.Runtime.InteropServices;
namespace ConsoleApplication2
{
public delegate bool CallBack(int hwnd, int
lParam);
public class EnumReportApp
{
[DllImport("user32")]
public static extern int EnumWindows
(CallBack x, int y);
public static void Main()
{
CallBack myCallBack = new CallBack
(EnumReportApp.Report);
EnumWindows(myCallBack, 0);
}
public static bool Report(int hwnd, int
lParam)
{
Console.Write("Window handle is ");
Console.WriteLine(hwnd);
return true;
}
}
}
please get back to me and let me know whether this does
the job for you.
Best regards
Peter Huang
--------------------
Content-Class: urn:content-classes:message
From: "Shai Levi" <
[email protected]>
Sender: "Shai Levi" <
[email protected]>
Subject: Migrating to Managed C++
Date: Tue, 15 Jul 2003 00:19:17 -0700
Lines: 28
Message-ID: <
[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE
V5.50.4910.0300
Thread-Index: AcNKoWcpcG037ES0R7yCWi4JcBMuqw==
Newsgroups: microsoft.public.dotnet.languages.vc
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.languages.vc:26165
NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
X-Tomcat-NG: microsoft.public.dotnet.languages.vc
Hi,
I'm trying to migrate native c++ class to managed c++
class.
The native class header definition looks as:
class NativeClass
{
public:
typedef void (CbFunc1)(int n,void* p);
typedef void (CbFunc2)(UnmanagedClass2& umc2,
void* p);
NativeClass();
~NativeClass();
BOOL SetCallback(CbFunc1*,void*);
BOOL SetCallback(CbFunc2*,void*);
VOID DoSomthing(int n);
};
The native class is in a separate dll. I read Platform
Invoke article and I found an exapmle for importing C
function from dll, How can I register managed class
method
as a call back function of native class?
Thanks, Shai Levi
.
.