A
albertos.email
Hello, I developed a DLL in eVC++ 4.0 for serial communications with a
CE 4.2 and a PPC2003. A test application in C++ revealed the Dll is
working correctly.
Now I want to use this same DLL in VB.net 2003. I created a VB Module
and imported the DLL. It all works just fine except when I try to use
the CreateFile() function from the DLL. It always returns False. I have
the following code in my Dll:
//Global
HANDLE hSerialPort;
DCB PortDCB;
int InitComPort(int port)
{
TCHAR portNum[10];
wsprintf(portNum,L"COM1:");
switch (port)
{
case '1': wsprintf(portNum,L"COM1:");
case '2': wsprintf(portNum,L"COM2:");
case '3': wsprintf(portNum,L"COM3:");
case '4': wsprintf(portNum,L"COM4:");
default : portNum[3] = port;
}
hSerialPort = CreateFile((LPCTSTR)portNum,GENERIC_READ |
GENERIC_WRITE,0,
NULL,OPEN_EXISTING,0,NULL);
if (hSerialPort == INVALID_HANDLE_VALUE)
{
return 0;
}
else if(hSerialPort != INVALID_HANDLE_VALUE)
{
return 1;
}
return 0;
}
Can someone help me use this function in VB.net as a C++ dll? Is the
Unicode the issue? My .def file contains the proper Export calls. I
tested with a test function with the following code for testing
purposes:
int test (int dec)
{
int newDec = 0;
newDec = dec + 1;
return newDec;
}
This test function works and returns the proper value. Any ideas? Could
VB.net not like CreatFile or the DCB structure for port settings?
CE 4.2 and a PPC2003. A test application in C++ revealed the Dll is
working correctly.
Now I want to use this same DLL in VB.net 2003. I created a VB Module
and imported the DLL. It all works just fine except when I try to use
the CreateFile() function from the DLL. It always returns False. I have
the following code in my Dll:
//Global
HANDLE hSerialPort;
DCB PortDCB;
int InitComPort(int port)
{
TCHAR portNum[10];
wsprintf(portNum,L"COM1:");
switch (port)
{
case '1': wsprintf(portNum,L"COM1:");
case '2': wsprintf(portNum,L"COM2:");
case '3': wsprintf(portNum,L"COM3:");
case '4': wsprintf(portNum,L"COM4:");
default : portNum[3] = port;
}
hSerialPort = CreateFile((LPCTSTR)portNum,GENERIC_READ |
GENERIC_WRITE,0,
NULL,OPEN_EXISTING,0,NULL);
if (hSerialPort == INVALID_HANDLE_VALUE)
{
return 0;
}
else if(hSerialPort != INVALID_HANDLE_VALUE)
{
return 1;
}
return 0;
}
Can someone help me use this function in VB.net as a C++ dll? Is the
Unicode the issue? My .def file contains the proper Export calls. I
tested with a test function with the following code for testing
purposes:
int test (int dec)
{
int newDec = 0;
newDec = dec + 1;
return newDec;
}
This test function works and returns the proper value. Any ideas? Could
VB.net not like CreatFile or the DCB structure for port settings?