The problem is with the argument list:
You have this:
HANDLE __stdcall GetDriverHandle(*The Problem*)
or, perhaps, this:
HANDLE __stdcall GetDriverHandle(const char ServiceName)
Either way, your C function expects a string to be passed by value (ByVal). However, when VB passes a string, regardless of whether the string is a literal or the value of a variable, what actually gets passed is a
pointer to the beginning of the string.
You should have this.
HANDLE __stdcall GetDriverHandle(LPCTSTR ServiceName)
HTH.
David Gray
Irving, Texas, USA
QUOTE(Servo Wizard @ 14 Oct, 2008 - 04:03 PM)

Hi,
My problem is with passing "\\\\.\\readios" from VB6 to C DLL. I can call the Function from VB6 and it returns the file handle, but only if I supply the data in the DLL code.
I need to replace *The Problem* in the C code with a declared variable that will accomplish the same as the ' const char* ' declaration in the code. Replacing the *The Problem* with the ' const char* ' declaration does not solve the problem.
Thanks in advance for helping,
Servo
Visual Basic 6.0:CODE
Option Explicit
Private Declare Function GetDriverHandle _
Lib "driverid.dll" ( _
ByVal ServiceName As String) As Long
Private Sub Form_Load()
Dim Service As String
Service = "\\\\.\\readios"
With DRO
.Text = GetDriverHandle(Service)
.SelStart = 0
.SelLength = Len(.Text)
.SelColor = &HFF00&
.SelLength = 0
End With
End Sub
Visual C 6.0:CODE
#include <stdio.h>
#include <windows.h>
BOOL APIENTRY DllMain(HANDLE hModule,DWORD dwMission,LPVOID lpReserved)
{
switch (dwMission)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH: break;
}
return TRUE;
}
HANDLE hFile;
HANDLE __stdcall GetDriverHandle(*The Problem*)
{
const char* ServiceName="\\\\.\\readios";
hFile=CreateFile
(
ServiceName,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);
return hFile;
}