从VB6.0调用C ++ DLL中的函数 [英] Calling A Function in C++ DLL from VB6.0
问题描述
大家好,我一直在尝试从VB6.0中调用C ++ DLL中的一个函数,但它不能正常工作。它会生成一条错误消息,指出"运行时错误49:错误的DLL调用约定"。
这个DLL的工作/功能是创建一个新的语音日志,它将连接到我的VoIP软件的各种用户的音频(对话)混合成MP3文件。
以下是我的代码,请仔细阅读并提供帮助。
提前致谢。
适用于VoiceLog.h(C / C ++标题)
//以下ifdef块是创建宏的标准方法,它使得从DLL中导出
//更简单。此DLL中的所有文件都使用命令行中定义的VOICELOG_EXPORTS
//符号进行编译。不应在使用此DLL的任何项目
//上定义此符号。这样,源文件包含此文件的任何其他项目都会看到
// VOICELOG_API函数从DLL导入,而此DLL看到使用此宏定义的符号
//正在导出。
#ifdef VOICELOG_EXPORTS
#define VOICELOG_API __declspec(dllexport)
#else
#define VOICELOG_API __declspec(dllimport)
#endif
# ifdef __cplusplus
extern"C" {
#endif
///创建一个新的语音日志,将音频混合到MP3文件中。
/// @param szTempDir存储临时文件的目录(.wav文件)
/// @param szMP3FileName MP3文件的输出路径,例如:
/// C:\conversation.mp3
/// @param nSecFlushInterval每次
///临时.wav文件混合并编码为MP3-之间的秒数格式。
/// @see VL_CloseVoiceLog
VOICELOG_API BOOL VL_CreateVoiceLog(IN LPCSTR szTempDir,
IN LPCSTR szMP3FileName,
IN INT32 nSecFlushInterval);
///关闭语音日志并完成编码到MP3文件中。
/// @param bAbort中止语音日志并跳过最终编码为
/// MP3文件。
/// @see VL_CreateVoiceLog
VOICELOG_API BOOL VL_CloseVoiceLog(IN BOOL bAbort);
///检查语音记录当前是否有效。
VOICELOG_API BOOL VL_IsVoiceLogging();
///将音频数据添加到语音日志中。确保将音频
///数据添加到语音日志中,当这个人真正开始
///谈话时,因为添加音频的时间被用作
///偏移当人完成讲话时,请拨打VL_EndStream(。)
///,以便语音记录器知道此人已停止说话。如果没有调用
/// VL_EndStream(。),语音记录器会认为
///人不停地说话而没有停顿。
///
/// @param nStreamID流的ID,例如:用户的ID。
/// @param nSampleRate正在添加的流的采样率
/// @param lpStreamData原始音频数据的音频缓冲区。
/// @param nSampleCount音频缓冲区中的样本数。
/// @see VL_EndStream
VOICELOG_API BOOL VL_AddStreamData(IN INT32 nStreamID,
IN INT32 nSampleRate,
IN CONST SHORT * lpStreamData,
IN INT32 nSampleCount);
///停止写一个特定的流,因为这个人不再是
///说话。
///
/// @param nStreamID流的ID,例如:用户的ID。
/// @see VL_AddStreamData
VOICELOG_API BOOL VL_EndStream(IN INT32 nStreamID);
#ifdef __cplusplus
};
#endif
从VB调用这个功能就是我做的。
我将下面的代码放在一般声明中
Option Explicit
Private Declare Function VL_CreateVoiceLog Lib" VoiceLog。 DLL" (ByVal szTempDir As String,ByVal szMP3FileName As String,ByVal nSecFlushInterval As Integer)As Long
我将下面的代码放在命令箱中;说CmdRecordConversation。该方法"接收已播放的音频的回叫"。并且它将调用一个事件。
Private Sub CmdRecordConversation_Click()
evoclient1.RegisterTalkingCallback
End Sub
以下是事件中的代码,这是我收到错误消息的地方。
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"
如果FExists(szMP3FileName)那么
szMP3FileName = szTempDir& " Conversation_" &安培; FileCountExist& " .MP3"
'开始创建mp3文件
VL_CreateVoiceLog szTempDir,szMP3FileName,nSecFlushInterval
否则
VL_CreateVoiceLog szTempDir,szMP3FileName,nSecFlushInterval
End if
End Sub
<这个论坛适用于VB.Net-only questsions。看看这里:
在哪里发布您的VB 6问题
Hello all, I have been trying to call a function in C++ DLL 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
Hi,
this forum is for VB.Net-only questsions. Have a look here: Where to post your VB 6 questions
这篇关于从VB6.0调用C ++ DLL中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!