Hi all,
I am new to .Net environment.
I have created a flat non-COM DLL from Visual C++ 6.0.
It stores up a function pointer from caller,
create a worker thread via WIN32 API,
and then call back the application within the worker thread.
Now, I created an application in VB.NET to use the DLL, and
it seems works fine.
I am not quite understand what is mananged and unmanaged code.
but seems that my DLL is called unmanaged code and
the code in VB is called managed code.
Is there any potential hazard in directly calling unmanaged DLL?
and also is it safe to call-back managed code from a thread in unmanaged
DLL?
What should I do in order to make it safe?
Here are some fragments of my code
In Application:
Module Module1
Public Declare Function RegisterEventHandler Lib "my.dll" _
Alias "_RegisterEventHandler@4" (ByVal lProcAddress As TEventHandler) _
As Integer
Delegate Sub TEventHandler(ByVal param As Integer)
Public Sub EventHandler(ByVal param As Integer)
Alter UI in Form1
.....
End Sub
End Module
Friend Class Form1
Inherits System.Windows.Forms.Form
Sub mySub()
RegisterEventHandler(AddressOf EventHandler)
End Sub
End Class
************************************************** *******
In DLL:
typedef void (CALLBACK* TEventHandler)(DWORD param);
TEventHandler EventHandler=NULL;
BOOL __declspec(dllexport) __stdcall RegisterEventHandler(long lProcAddress)
{
EventHandler = lProcAddress
hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&worker, NULL,
0, &pThreadId);
Return TRUE;
};
void worker(LPVOID lpParam)
{
....
loop{
EventHandler(param);
}
}