5 Replies - 5474 Views - Last Post: 30 August 2012 - 08:40 PM Rate Topic: -----

#1 programmermja  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 6
  • Joined: 25-December 10

Calling A Function in C++ DLL from VB6.0

Posted 31 July 2012 - 05:38 PM

Hello all, I have been trying to call a function in C++ from VB6.0 but its not working as suppose. It do generate an error message saying "Run-time error 49: Bad DLL calling convention".
The work/function of this DLL is to Create a new voice-log which mixes audio(conversation) of various users connected to my VoIP software into a MP3 file.
Below are my codes, Please go through it and help.
Thanks in advance.


For VoiceLog.h(C/C++ Header)
// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the VOICELOG_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see 
// VOICELOG_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef VOICELOG_EXPORTS
#define VOICELOG_API __declspec(dllexport)
#else
#define VOICELOG_API __declspec(dllimport)
#endif

#ifdef __cplusplus
extern "C" {
#endif

	/// Create a new voice-log which mixes audio into a MP3 file.
	/// @param szTempDir The directory to store temporary files (.wav files)
	/// @param szMP3FileName The output path of the MP3 file, e.g. 
	/// C:\conversation.mp3
	/// @param nSecFlushInterval The number of seconds between each time
	/// the temporary .wav files are mixed and encoded into MP3-format.
	/// @see VL_CloseVoiceLog
	VOICELOG_API BOOL VL_CreateVoiceLog(IN LPCSTR szTempDir, 
		IN LPCSTR szMP3FileName, 
		IN INT32 nSecFlushInterval);

	/// Close the voice-log and finish encoding into the MP3 file.
	/// @param bAbort Abort the voice-log and skip final encoding to
	/// the MP3 file.
	/// @see VL_CreateVoiceLog
	VOICELOG_API BOOL VL_CloseVoiceLog(IN BOOL bAbort);

	/// Check if voice-logging is currently active.
	VOICELOG_API BOOL VL_IsVoiceLogging();

	/// Add audio data to the voice-log. Make sure to add the audio
	/// data to the voice-log when the person is actually starting 
	/// to talk since the time of when the audio is added is used as 
	/// offset. When the person is finished talking call VL_EndStream(.)
	/// so the voice-logger knows the person has stopped talking. If
	/// VL_EndStream(.) is not called the voice-logger will think the
	/// person is constantly talking without pauses.
	///
	/// @param nStreamID The ID of the stream, e.g. the user's ID.
	/// @param nSampleRate The sample rate of the stream being added
	/// @param lpStreamData The audio buffer of raw audio data.
	/// @param nSampleCount The number of samples in the audio buffer.
	/// @see VL_EndStream
	VOICELOG_API BOOL VL_AddStreamData(IN INT32 nStreamID, 
		IN INT32 nSampleRate, 
		IN CONST SHORT* lpStreamData,
		IN INT32 nSampleCount);

	/// Stop writing to a specific stream since the person is no longer
	/// talking.
	///
	/// @param nStreamID The ID of the stream, e.g. the user's ID.
	/// @see VL_AddStreamData
	VOICELOG_API BOOL VL_EndStream(IN INT32 nStreamID);

#ifdef __cplusplus
};
#endif




Calling the function from VB this was what I did.
I placed the code below in the general declaration
Option Explicit
Private Declare Function VL_CreateVoiceLog Lib "VoiceLog.dll" (ByVal szTempDir As String, ByVal szMP3FileName As String, ByVal nSecFlushInterval As Integer) As Long



I placed the code below in a commandbox; say CmdRecordConversation. This method "Receive callbacks of audio which has been played" and it will invoke an event.
Private Sub CmdRecordConversation_Click()
evoclient1.RegisterTalkingCallback
End Sub



Below is the code in the event and this is where I get error message.

Private Sub evoclient1_OnUserAudioData(ByVal nUserID As Long, ByVal nSampleRate As Long, pRawAudio() As Integer, ByVal nSamples As Long)
Dim szTempDir, szMP3FileName As String
Dim FileCountExist As Long
Dim nSecFlushInterval As Integer
nSecFlushInterval = 10
szTempDir = GetSetting(App.EXEName, App.EXEName, "Default Path") & "\"
FileCountExist = filecount(szTempDir) + 1
szMP3FileName = szTempDir & "Conversation.mp3"
If FExists(szMP3FileName) Then
    szMP3FileName = szTempDir & "Conversation_" & FileCountExist & ".mp3"
    'Start creating mp3 file
    VL_CreateVoiceLog szTempDir, szMP3FileName, nSecFlushInterval
Else
    VL_CreateVoiceLog szTempDir, szMP3FileName, nSecFlushInterval
End If
End Sub

Attached File(s)


This post has been edited by GunnerInc: 31 July 2012 - 05:44 PM
Reason for edit:: Removed bigish font size


Is This A Good Question/Topic? 0
  • +

Replies To: Calling A Function in C++ DLL from VB6.0

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: Calling A Function in C++ DLL from VB6.0

Posted 31 July 2012 - 05:45 PM

Please take it easy on the big fonts...
Was This Post Helpful? 0
  • +
  • -

#3 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Calling A Function in C++ DLL from VB6.0

Posted 01 August 2012 - 03:04 PM

Clearly, you didn't try googling "bad dll calling convention". Why not?
Was This Post Helpful? 0
  • +
  • -

#4 programmermja  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 6
  • Joined: 25-December 10

Re: Calling A Function in C++ DLL from VB6.0

Posted 09 August 2012 - 05:50 PM

View PostBobRodes, on 01 August 2012 - 03:04 PM, said:

Clearly, you didn't try googling "bad dll calling convention". Why not?


I did.
Was This Post Helpful? 0
  • +
  • -

#5 Neku  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 268
  • Joined: 21-May 09

Re: Calling A Function in C++ DLL from VB6.0

Posted 10 August 2012 - 07:30 AM

and...? what you got?
Was This Post Helpful? 0
  • +
  • -

#6 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Calling A Function in C++ DLL from VB6.0

Posted 30 August 2012 - 08:40 PM

Well, the answer is quite obvious to anyone reading the Microsoft page on the subject, at least anyone who really wrote the code the OP posted as he appears to be claiming. OP is passing an argument ByRef instead of ByVal or the reverse.

This post has been edited by BobRodes: 30 August 2012 - 08:41 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1