eVC++ 4.0 Dll In VB.net 2003

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?
 
G

Guest

Your VB app is never calling CreateFile - it's calling InitComPort (there
are lots of free libraries existing that would allow this - OpenNETCF's or
Dick Grier's come to mind, so no idea why you're even doing this). How are
you determining CreateFile is returning false? I also have no idea what
you're switch statement is supposed to be doing. There are no break's in
there, so everything just falls through to the defaults which sets a TCHAR
to a number (does that even compile?).

I mean why not just do this:

_stprintf(portNum, _T("COM%i:"), port);
 

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