hi,
I made a 'dll' which records voice.
and I called the function in eVB.
It gives no errors. But the voice was not recorded.
what's wrong with my program?
could you comment it?
thank a lot in advance.
here are my source codes.
///////////////////////////////////
// eVB xxx.vb
//////////////////////////////////
Option Explicit
Public Declare Function CreateVoiceControl Lib "VoiceControl.dll" (ByVal
hwndMain As Long) As Long
Public Declare Function RecordVoice Lib "VoiceControl.dll" (ByVal hVoice As
Long) As Integer
Public Declare Function StopRecordVoice Lib "VoiceControl.dll" (ByVal hVoice
As Long) As Integer
Public Declare Sub setTest Lib "VoiceControl.dll" (ByVal i As Integer)
Public Declare Function getTest Lib "VoiceControl.dll" () As Integer
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
Public Declare Function PlaySound Lib "Coredll" Alias "PlaySoundW" _
(ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long)
As Long
Dim a
Private Sub Command1_Click()
a = CreateVoiceControl(Me.hWnd)
If (a = Null) Then
MsgBox "failed"
Else
MsgBox "succeed=" + CStr(a)
End If
End Sub
Private Sub Command2_Click()
Dim b
b = RecordVoice(a)
If (b = Null) Then
MsgBox "failed"
Else
MsgBox "succeed=" + CStr(b)
End If
End Sub
Private Sub Command3_Click()
Dim b
b = StopRecordVoice(a)
If (b = Null) Then
MsgBox "failed"
Else
MsgBox "succeed=" + CStr(b)
End If
End Sub
Private Sub Command4_Click()
' Dim MySound As Long
' Dim FName As String
' FName = "\Program Files\EzPims\memotemp.wav"
'
' MySound = PlaySound(FName, vbNull, SND_ASYNC)
MsgBox CStr(fnAaa())
End Sub
Private Sub Command5_Click()
Call setTest(6)
MsgBox "setdone with 6"
End Sub
Private Sub Command6_Click()
Dim i
i = getTest
MsgBox CStr(i)
End Sub
Private Sub Form_OKClick()
App.End
End Sub
Private Sub Form_Unload(Cancel As Integer)
a = Nothing
End Sub
///////////////////////////////////
// voiceControlHead.h
//////////////////////////////////
#ifdef __cplusplus
extern "C" {
#endif
// Your function headers go here
#ifdef __cplusplus
Quote:
}
#endif
#ifdef MYDLL_IMPLEMENTATION
#define DLLEXPORT _declspec(dllexport) HWND CreateVoiceControl (HWND
hwndMain);
#define DLLEXPORT _declspec(dllexport) LRESULT RecordVoice (HWND hVoice);
#define DLLEXPORT _declspec(dllexport) LRESULT StopRecordVoice (HWND
hVoice);
#define DLLEXPORT _declspec(dllexport) void setTest (int i);
#define DLLEXPORT _declspec(dllexport) int getTest ();
#else
#define DLLEXPORT _declspec(dllimport)
#endif
///////////////////////////////////
// voiceControl.h
//////////////////////////////////
#if
!defined(AFX_VOICECONTROL_H__4A49D143_6150_4101_BCA5_E19B138E33D9__INCLUDED_
)
#define AFX_VOICECONTROL_H__4A49D143_6150_4101_BCA5_E19B138E33D9__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
////////////////////////////////////////////////////////////////////////////
/
// CVoiceControlApp
// See VoiceControl.cpp for the implementation of this class
//
class CVoiceControlApp : public CWinApp
{
public:
CVoiceControlApp();
HWND hwndVoice;
int test ;
// Overrides
// ClassWizard generated virtual function overrides
///{{AFX_VIRTUAL(CVoiceControlApp)
/// }}AFX_VIRTUAL
/// //{{AFX_MSG(CVoiceControlApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
/// //}}AFX_MSG
DECLARE_MESSAGE_MAP()
Quote:
};
////////////////////////////////////////////////////////////////////////////
/
///{{AFX_INSERT_LOCATION}}
// Microsoft eMbedded Visual C++ will insert additional declarations
immediately before the previous line.
#endif //
!defined(AFX_VOICECONTROL_H__4A49D143_6150_4101_BCA5_E19B138E33D9__INCLUDED_
)
///////////////////////////////////
// voiceControl.cpp
//////////////////////////////////
#include "stdafx.h"
#include "VoiceControl.h"
#include "VoiceControlHead.h"
#include <voicectl.h>
#define MYDLL_IMPLEMENTATION
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
////////////////////////////////////////////////////////////////////////////
/
// The one and only CVoiceControlApp object
CVoiceControlApp theApp;
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL Pascal EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
////////////////////////////////////////////////////////////////////////////
/
// CVoiceControlApp
BEGIN_MESSAGE_MAP(CVoiceControlApp, CWinApp)
///{{AFX_MSG_MAP(CVoiceControlApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
/// }}AFX_MSG_MAP
END_MESSAGE_MAP()
////////////////////////////////////////////////////////////////////////////
/
// CVoiceControlApp construction
CVoiceControlApp::CVoiceControlApp()
{
/* CM_VOICE_RECORDER cmvr;
memset( &(cmvr), 0, sizeof(cmvr));
cmvr.cb = sizeof (CM_VOICE_RECORDER);
cmvr.dwStyle = VRS_NO_MOVE;
cmvr.xPos = -1; ///-1 means cont
rol is drawn centered to Parent window hwndMain
cmvr.yPos = 160;
cmvr.hwndParent = NULL;
cmvr.id = NULL;
///cmvr.lpszRecordFileName = TEXT("\\My Documents\\memotemp.wav");
cmvr.lpszRecordFileName = TEXT("\\Program Files\\EzPims\\memotemp.wav");
theApp.hwndVoice = VoiceRecorder_Create (&cmvr);
theApp.test = 1;
// TODO: add construction code here,
// Place all significant initialization in InitInstance
// CreateVoiceControl();
*/
Quote:
}
extern "C" _declspec(dllexport) HWND CreateVoiceControl (HWND hwndMain)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CM_VOICE_RECORDER cmvr;
memset( &(cmvr), 0, sizeof(cmvr));
cmvr.cb = sizeof (CM_VOICE_RECORDER);
cmvr.dwStyle = VRS_NO_MOVE;
cmvr.xPos = -1; /// means control is drawn centered to Parent window
hwndMain
cmvr.yPos = 160;
cmvr.hwndParent = hwndMain;
cmvr.id = NULL;
cmvr.lpszRecordFileName = TEXT("\\Program Files\\EzPims\\memotemp.wav");
theApp.hwndVoice = VoiceRecorder_Create (&cmvr);
// SendMessage (theApp.hwndVoice, VRM_RECORD, 0, (LPARAM) (LPTSTR)
TEXT("\\Program Files\\EzPims\\memotemp.wav"));
// Sleep(3000);
// SendMessage (theApp.hwndVoice, VRM_STOP, 0, 0);
return theApp.hwndVoice ;
Quote:
}
extern "C" _declspec(dllexport) LRESULT RecordVoice (HWND hVoice)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
LRESULT a;
// if (hVoice != NULL){
if( (hVoice == theApp.hwndVoice) && (hVoice!=NULL)){
a = SendMessage (theApp.hwndVoice, VRM_RECORD, 0, (LPARAM) (LPTSTR) TEXT("\\Program Files\\EzPims\\memotemp.wav"));
return a ; }
return -1;
Quote:
}
extern "C" _declspec(dllexport) LRESULT StopRecordVoice (HWND hVoice)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
LRESULT a;
// if (hVoice != NULL) {
if( (hVoice == theApp.hwndVoice) && (hVoice!=NULL)){
a=SendMessage (theApp.hwndVoice, VRM_STOP, 0, 0);
return a; }
return -1;
Quote:
}
extern "C" _declspec(dllexport) void setTest (int i)
{
theApp.test = i;
return;
Quote:
}
extern "C" _declspec(dllexport) int getTest (){
return theApp.test;
Quote:
}