Solved

help referencing  a function in a dll from vb6

Posted on 2013-01-23
20
555 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
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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 45

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 27

Accepted Solution

by:
Ark earned 500 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 27

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
message box in access 4 46
How do I save this device context as a .bmp or a picture of some kind? 2 57
Problem to With line 4 57
DCT of  2D array using fftw in c++ 9 38
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

776 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