First of all, your explanation of possible malfunction of
SetConnectPort
and
OpenDeviceEx
is wrong. If a DLL is loaded, it behaves like a normal executable module with all its static memory preserved, so you can consider that its internal state, if any, is preserved during execution. There is nothing you should take care of.
It is not clear why would you obtain the access to these two functions using
LoadLibrary
and
GetProcAddress
. You could P/Invoke them exactly as you did it with
LoadLibrary
and
GetProcAddress
themselves; and it would be more reliable approach.
Finally, if you have a printer that can work via TCP, you could fully use it through the class
System.Net.Sockets.TcpClient
,
http://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient.aspx[
^]. It would not require P/Invoke at all and be fully portable, work on any OS.
[EDIT]
I assumed it's given, but maybe it won't hurt to remind you, that is a standard printer device, you could install it in the system in a standard way and use it in your applications as any other printer.
—SA