Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

help referencing  a function in a dll from vb6

Posted on 2013-01-23
20
Medium Priority
?
596 Views
Last Modified: 2013-01-30
i have a function "VDLDLL_VSFileToWaveFile" that i need to access in my VB6 application. the examples given for the dll are both in c++ and delphi:

 C/C++
short VSFileToWaveFile(char * from_fl , char *to_fl, short uncompress). 

 

Delphi
Function VDLDLL_VSFileToWaveFile(from_fl,to_fl: PChar; uncompress: Short): Short; cdecl;  external 'vsclt300.dll';

 

This function converts a VSLogger recording file to a .WAV file. 

From_fl and to_fl are the full path to the origin and destination files.

Uncompress = 1, creates uncompressed file (PCM 16, 8 KHz)

Uncompress = 0, leaves audio compressed in the Wave file

You can use the following function in your program to read the header from wave files.

 

mmio.. functions declarations

 Header: Mmsystem.h; include Windows.h.

 Library: Use Winmm.lib.

 

short VSHeaderFromWaveFile(char * wv_fl , RECORD_BLOCK * recbl) 

{ 

 

 HMMIO mmioHdl; 

 MMCKINFO waveRIFF;                       // (OUT)  

 MMCKINFO vslgRIFF;                    // (OUT)  

 int nError; 

 

 mmioHdl = mmioOpen(wv_fl, NULL,  

  MMIO_ALLOCBUF | MMIO_READ );  

  

 if (mmioHdl == NULL)  

 {  

  return 0;  

 }  

 

 nError = mmioSeek(mmioHdl, 0, SEEK_SET);  

 /* Open the file RIFF chunk of form type 'WAVE'.  

   */  

 waveRIFF.fccType = mmioFOURCC('W', 'A', 'V', 'E');         

 waveRIFF.cksize = 0;   

 if ((nError = mmioDescend(mmioHdl, &waveRIFF, NULL, MMIO_FINDRIFF)) != 0)  

 { 

  mmioClose(mmioHdl, 0);  

  return 0;  

 } 

 

 vslgRIFF.ckid = mmioFOURCC('v', 's', 'l', 'g');         

 if ((nError = mmioDescend(mmioHdl, &vslgRIFF,&waveRIFF, MMIO_FINDCHUNK)) != 0)  

 { 

  mmioClose(mmioHdl, 0);  

  return 0;  

 } 

 

 if (mmioRead(mmioHdl, (HPSTR)recbl, sizeof(RECORD_BLOCK)) !=  sizeof(RECORD_BLOCK))  

 { 

  mmioClose(mmioHdl, 0);  

  return 0;  

 } 

 else 

  mmioClose(mmioHdl, 0);  

 

 return 1; 

} 

Open in new window


when i run the following code:
Option Explicit
Private Declare Function VDLDLL_VSFileToWaveFile Lib "C:\Program Files\Versadial Solutions\vsLogger\vsclt300.dll" (from_fl As String, to_fl As String, uncompress As Integer) As Integer
'Private Declare Function VDLDLL_VSFileToWaveFile Lib "C:\Program Files\Versadial Solutions\vsLogger\vsclt300.dll" (ByVal from_fl As String, to_fl As String, uncompress As Integer) As integer
'Private Declare Function VDLDLL_VSFileToWaveFile Lib "C:\Program Files\Versadial Solutions\vsLogger\vsclt300.dll" (ByVal from_fl As String, ByVal to_fl As String, uncompress As Integer) As Integer
'Private Declare Function VDLDLL_VSFileToWaveFile Lib "C:\Program Files\Versadial Solutions\vsLogger\vsclt300.dll" (ByVal from_fl As String, to_fl As String, ByVal uncompress As Integer) As Integer
'Private Declare Function VDLDLL_VSFileToWaveFile Lib "C:\Program Files\Versadial Solutions\vsLogger\vsclt300.dll" (from_fl As String, ByVal to_fl As String, uncompress As Integer) As Integer
'Private Declare Function VDLDLL_VSFileToWaveFile Lib "C:\Program Files\Versadial Solutions\vsLogger\vsclt300.dll" (from_fl As String, ByVal to_fl As String, ByVal uncompress As Integer) As Integer
'Private Declare Function VDLDLL_VSFileToWaveFile Lib "C:\Program Files\Versadial Solutions\vsLogger\vsclt300.dll" (from_fl As String, to_fl As String, ByVal uncompress As Integer) As Integer
'Private Declare Function VDLDLL_VSFileToWaveFile Lib "C:\Program Files\Versadial Solutions\vsLogger\vsclt300.dll" (ByVal from_fl As String, ByVal to_fl As String, ByVal uncompress As Integer) As Integer

Dim i As Integer
Private Sub Form_Load()
Dim from As String
Dim dest As String
Dim comp As Integer
from = "C:\temp\130122094708.C006"
dest = "C:\temp\130122094708.C006.wav"
comp = 1
i = VDLDLL_VSFileToWaveFile(StrPtr(from), StrPtr(dest), StrPtr(comp))
MsgBox i
End Sub

Open in new window


i get a run time error '6': overflow
and the error occurs on "i = VDLDLL_VSFileToWaveFile(StrPtr(from), StrPtr(dest), StrPtr(comp))"

any ideas  on how to get this working in my vb6 program
would be greatly appreciated
0
Comment
Question by:brainomite
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 3
  • +3
20 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 38812053
'uncompress' is 'short', i.e a 16-bit value, where you are declaring and calling it as a 32-bit integer, thus probably the overflow - try declaring it as the VB equivalent to 'short'.
0
 

Author Comment

by:brainomite
ID: 38812150
unfortunately from what i gather, integer is "short" i'm not seeing any doc that does the short equiv of delphi's short. in the link they reference .net's short value
link
0
 
LVL 86

Expert Comment

by:jkr
ID: 38812230
Well, I don't know too much about VB, but according to http://msdn.microsoft.com/en-us/library/47zceaw7%28v=VS.80%29.aspx ("Data Type Summary (Visual Basic)  "), it should be 'UInt16'
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:brainomite
ID: 38812242
that data type doesn't exist in vb6 :( tried both UInt16 and UShort
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 38812277
Have you tried?
Dim i as Long

Open in new window

0
 

Author Comment

by:brainomite
ID: 38812281
i've tried long, double and single in addition to int for the variable i
0
 
LVL 86

Expert Comment

by:jkr
ID: 38812291
Hm, that'd really surprise me - stupid quesiton, have you tried 'Short' (http://msdn.microsoft.com/en-US/library/7tb7bdw6%28v=vs.80%29.aspx)? ;o)
0
 

Author Comment

by:brainomite
ID: 38812311
jkr:
#1, link doesn't work
#2 just did and i get "user-defined type not defined"
0
 
LVL 86

Expert Comment

by:jkr
ID: 38812409
Argh, EE added the ')' to the link, that should be http://msdn.microsoft.com/en-US/library/7tb7bdw6%28v=vs.80%29.aspx
0
 

Author Comment

by:brainomite
ID: 38813905
JKr,

ok yeah that worked.
the article references is referring to vb 2005, i'm several versions behind in 6.0
0
 
LVL 15

Expert Comment

by:eemit
ID: 38814334
Try:
Private Declare Function VDLDLL_VSFileToWaveFile Lib "C:\Program Files\Versadial Solutions\vsLogger\vsclt300.dll" (from_fl As String, to_fl As String, ByVal uncompress As Integer) As Integer

Open in new window

And:
i = VDLDLL_VSFileToWaveFile(StrPtr(from), StrPtr(dest), ByVal comp)

Open in new window

0
 

Author Comment

by:brainomite
ID: 38814353
eemit:

i get  run-time error '49':

Bad DLL calling convention
0
 
LVL 15

Expert Comment

by:eemit
ID: 38816160
Try either:
Private Declare Function VDLDLL_VSFileToWaveFile Lib "C:\Program Files\Versadial Solutions\vsLogger\vsclt300.dll" (ByVal from_fl As String, ByVal to_fl As String, ByVal uncompress As Integer) As Integer

Open in new window

And:
i = VDLDLL_VSFileToWaveFile(from, dest, ByVal comp)

Open in new window


Or:
Private Declare Function VDLDLL_VSFileToWaveFile Lib "C:\Program Files\Versadial Solutions\vsLogger\vsclt300.dll" (ByVal from_fl As Long, ByVal to_fl As Long, ByVal uncompress As Integer) As Integer

Open in new window

And:
i = VDLDLL_VSFileToWaveFile(StrPtr(from), StrPtr(dest), ByVal comp)

Open in new window

0
 

Author Comment

by:brainomite
ID: 38816284
eemit:

they both  gave the same 49 error as earlier
0
 
LVL 15

Expert Comment

by:eemit
ID: 38816383
It seems that the DLL isn't meant to be used from VB6
0
 
LVL 46

Expert Comment

by:aikimark
ID: 38816631
A little clarity.
Function VDLDLL_VSFileToWaveFile(from_fl,to_fl: PChar; uncompress: Short): Short; cdecl;  external 'vsclt300.dll';

Open in new window


From the Delphi definition, we see that the from and to parameters are of type PChar.  This is a null-delimited ASCII string.  Your VB strings are unicode.  You will probably need to do something like the following:
Option Explicit
Private Declare Function VDLDLL_VSFileToWaveFile Lib "C:\Program Files\Versadial Solutions\vsLogger\vsclt300.dll" (from_fl As String, to_fl As String, uncompress As Integer) As Integer
'Private Declare Function VDLDLL_VSFileToWaveFile Lib "C:\Program Files\Versadial Solutions\vsLogger\vsclt300.dll" (ByVal from_fl As String, to_fl As String, uncompress As Integer) As integer
'Private Declare Function VDLDLL_VSFileToWaveFile Lib "C:\Program Files\Versadial Solutions\vsLogger\vsclt300.dll" (ByVal from_fl As String, ByVal to_fl As String, uncompress As Integer) As Integer
'Private Declare Function VDLDLL_VSFileToWaveFile Lib "C:\Program Files\Versadial Solutions\vsLogger\vsclt300.dll" (ByVal from_fl As String, to_fl As String, ByVal uncompress As Integer) As Integer
'Private Declare Function VDLDLL_VSFileToWaveFile Lib "C:\Program Files\Versadial Solutions\vsLogger\vsclt300.dll" (from_fl As String, ByVal to_fl As String, uncompress As Integer) As Integer
'Private Declare Function VDLDLL_VSFileToWaveFile Lib "C:\Program Files\Versadial Solutions\vsLogger\vsclt300.dll" (from_fl As String, ByVal to_fl As String, ByVal uncompress As Integer) As Integer
'Private Declare Function VDLDLL_VSFileToWaveFile Lib "C:\Program Files\Versadial Solutions\vsLogger\vsclt300.dll" (from_fl As String, to_fl As String, ByVal uncompress As Integer) As Integer
'Private Declare Function VDLDLL_VSFileToWaveFile Lib "C:\Program Files\Versadial Solutions\vsLogger\vsclt300.dll" (ByVal from_fl As String, ByVal to_fl As String, ByVal uncompress As Integer) As Integer

Dim i As Integer
Private Sub Form_Load()
Dim from As String
Dim dest As String
Dim comp As Integer
Dim bFrom() as Byte
Dim bDest() as Byte

from = "C:\temp\130122094708.C006"
bFrom = StrConv(from, vbFromUnicode)
dest = "C:\temp\130122094708.C006.wav"
bDest = StrConv(dest, vbFromUnicode)
ReDim Preserve bFrom(0 To Ubound(bFrom) + 1)
ReDim Preserve bDest(0 To Ubound(bDest) + 1)

comp = 1
i = VDLDLL_VSFileToWaveFile(bFrom(0), bDest(0), StrPtr(comp))
MsgBox i
End Sub

Open in new window

0
 
LVL 28

Accepted Solution

by:
Ark earned 2000 total points
ID: 38816781
Short; cdecl;  external 'vsclt300.dll'
VB6 doesn't support cdecl - in all cases you'll get err 49. Recompile dll with stdcall

PS. Actually, you CAN call cdecl functions from VB - see my sample at http://www.freevbcode.com/ShowCode.asp?ID=1863, but it can cause memory leak since cdecl functions doesn't free it's internal buffer
0
 
LVL 86

Expert Comment

by:jkr
ID: 38819794
OK, let's try something unconventional to circumvent VB6 being short of 'short'

#include <windows.h>

typedef short (*FPTR_VSFileToWaveFile)(char *, char *, short).;

extern "C"
__declspec(dllexport)
short CallVSFileToWaveFile(char * from , char *to, int uncompress). {

  FPTR_VSFileToWaveFile pFunc;

  HINSTANCE hDll = LoadLibrary("the_dll_name_here");

  if (!hDll) return -1;

  pFunc = (FPTR_VSFileToWaveFile) GetProAddress(hDll, "VSFileToWaveFile");

  if (!pFunc) {

    FreeLibrary(hDll);

    return -2;
 }
 
  short sRet = (*pFunc)(from,to,(short)uncompress);

  FreeLibrary(hDll);

  return sRet;
}

Open in new window


Compile that with Visual Studio and call the above wrapper function...
0
 

Author Comment

by:brainomite
ID: 38819881
i'll be continuing to work on the above next week, i'm off site at this time, for now thanks for the ideas, i'm not ignoring anyone
0
 
LVL 28

Expert Comment

by:Ark
ID: 38821024
__declspec(dllexport)
short CallVSFileToWaveFile
Should be
__declspec(dllexport)
short __stdcall CallVSFileToWaveFile

Open in new window

to use in VB6 (or use /Gz option when compiling)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question