Solved

help referencing  a function in a dll from vb6

Posted on 2013-01-23
20
531 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
 

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now