Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 617
  • Last Modified:

help referencing a function in a dll from vb6

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
brainomite
Asked:
brainomite
  • 8
  • 5
  • 3
  • +3
1 Solution
 
jkrCommented:
'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
 
brainomiteAuthor Commented:
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
 
jkrCommented:
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
brainomiteAuthor Commented:
that data type doesn't exist in vb6 :( tried both UInt16 and UShort
0
 
GrahamSkanRetiredCommented:
Have you tried?
Dim i as Long

Open in new window

0
 
brainomiteAuthor Commented:
i've tried long, double and single in addition to int for the variable i
0
 
jkrCommented:
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
 
brainomiteAuthor Commented:
jkr:
#1, link doesn't work
#2 just did and i get "user-defined type not defined"
0
 
jkrCommented:
Argh, EE added the ')' to the link, that should be http://msdn.microsoft.com/en-US/library/7tb7bdw6%28v=vs.80%29.aspx
0
 
brainomiteAuthor Commented:
JKr,

ok yeah that worked.
the article references is referring to vb 2005, i'm several versions behind in 6.0
0
 
eemitCommented:
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
 
brainomiteAuthor Commented:
eemit:

i get  run-time error '49':

Bad DLL calling convention
0
 
eemitCommented:
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
 
brainomiteAuthor Commented:
eemit:

they both  gave the same 49 error as earlier
0
 
eemitCommented:
It seems that the DLL isn't meant to be used from VB6
0
 
aikimarkCommented:
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
 
ArkCommented:
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
 
jkrCommented:
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
 
brainomiteAuthor Commented:
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
 
ArkCommented:
__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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 8
  • 5
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now