vb.net app + C Dll

S

SteM

Hi all,
i'm developing a project where the gui is written with vb.net VS 2005
Express.
I wrote a C DLL (VC6) when i put the serial communication.
Since the communication should be slow i need absolutely that vb makes
asynchronous calls.
Which solution is better:
- synchrounous vb call in a dirrerent vb process
- async call and the DLL creates a separate thread for the communication

How can i notify the vb appl that data are coming?
Which mechanism vb.net has ???

Thanks !
 
K

kimiraikkonen

Hi all,
i'm developing a project where the gui is written with vb.net VS 2005
Express.
I wrote a C DLL (VC6) when i put the serial communication.
Since the communication should be slow i need absolutely that vb makes
asynchronous calls.
Which solution is better:
- synchrounous vb call in a dirrerent vb process
- async call and the DLL creates a separate thread for the communication

How can i notify the vb appl that data are coming?
Which mechanism vb.net has ???

Thanks !

Your C Dll is probably written without .NET (as you stated VC6) that
means it's unmaged. To reach your functions / methods, you need to p/
invoke to your DLL which is quite hard unless you know the correct p/
invoke declaration / usage through your DLL.

So, If you're sure how to implement the same serial functions to
your .NET app, use .NET classes(eg. serial port class), else search
Google for p/invoke demonstrations.

Regards
 
S

SteM

Your C Dll is probably written without .NET (as you stated VC6) that
means it's unmaged. To reach your functions / methods, you need to p/
invoke to your DLL which is quite hard unless you know the correct p/
invoke declaration / usage through your DLL.

Right.
I solved with a sintax equal to VB6 one:
public declare sub Fn lib "xxx" alias "XXX" () ...
and it works !

Right now my problem is how to notify the end of the operations from the DLL
to the vb.net application !
Is there any events or callbacks or other between .net and unmanaged ???

Thanks !
 
A

Armin Zingler

SteM said:
Right.
I solved with a sintax equal to VB6 one:
public declare sub Fn lib "xxx" alias "XXX" () ...
and it works !

Right now my problem is how to notify the end of the operations from
the DLL to the vb.net application !
Is there any events or callbacks or other between .net and unmanaged
???

It's possible if the DLL provides a feedback mechanism. If the function
declared above does not have a callback address parameter, you will
never know. Or, you will have to find another function that can be
called in a Timer's Tick event. Or, even less probable, there is another
function that can be called to add a callback address, similar to
"AddHandler".


Armin
 
S

SteM

Your C Dll is probably written without .NET (as you stated VC6)
It's possible if the DLL provides a feedback mechanism. If the function
declared above does not have a callback address parameter, you will
never know. Or, you will have to find another function that can be
called in a Timer's Tick event. Or, even less probable, there is another
function that can be called to add a callback address, similar to
"AddHandler".

How is possible a callback mechanism .. addresses are not valid in each
other environment !
Or is there a way to magically use the other address ??

Thanks !!
 
A

Armin Zingler

SteM said:
How is possible a callback mechanism .. addresses are not valid in
each other environment !
Or is there a way to magically use the other address ??

First you have to know if the dll offers a callback mechanism. If it
doesn't, you don't have to know how to do it. However, if it's possible,
have a look here: http://msdn2.microsoft.com/en-us/library/d186xcf0.aspx
(in addition the how-to linked at the bottom)


Armin
 
T

Tom Shelton

How is possible a callback mechanism .. addresses are not valid in each
other environment !

A dll is mapped into the current process adress space, so function
address passed by the main process are valid in the dll. Look at examples,
like EnumWindows etc.

Basically, the C/C++ code will define a function pointer. That will map
to a Delegate on the managed side (a delegate is a function pointer).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top