C#调用VC写的DLL问题,急,在线等,问题解决,马上结贴
VC代码:
//视频数据回调函数
void __cdecl StreamDataProc(char *csFrontID, int iChannelNo, char *frameData, int frameLen, LPVOID callbackParam)
{
CClientDemoDlg* pClientDlg = (CClientDemoDlg*)callbackParam;
if (memcmp(pClientDlg->m_csFrontID, csFrontID, VS_FRONTID_LEN) == 0 && pClientDlg->m_iChannelNo == iChannelNo)
{
PlaySDK_SendOneFrame(pClientDlg->m_hPlaySession, (unsigned char *)frameData, frameLen);
if (pClientDlg->m_bRecording)
{
AVRecord_sendOneFrame(pClientDlg->m_hRecHandle, frameData, frameLen);
}
else if (pClientDlg->m_bRec)
{
VSFrameHeader *pHeader = (VSFrameHeader*)frameData;
//注意,录像时的第一帧必须是I帧
if (pHeader->bIFrame)
{
//btl:自定义格式,文件后缀.gh;avi:avi格式,文件后缀.avi
pClientDlg->m_hRecHandle = AVRecord_create("btl");
char cFileName[1024];
memset(cFileName, 0, sizeof(cFileName));
sprintf(cFileName, "D:\\%s_%s_channel%d.gh",
pClientDlg->m_csFrontID, pClientDlg->GetCurDT(2), pClientDlg->m_iChannelNo);
AVRecord_setVideoFormat(pClientDlg->m_hRecHandle, C_FORMAT_H264,
pClientDlg->m_iImageWidth, pClientDlg->m_iImageHeight, pClientDlg->m_iFramerate);
AVRecord_setAudioFormat(pClientDlg->m_hRecHandle,
C_FORMAT_MP3, 1, 8000, 16, 16000);
AVRecord_setCallBackFun(pClientDlg->m_hRecHandle, NULL, NULL, 0);
AVRecord_setRecordFileName(pClientDlg->m_hRecHandle, cFileName);
AVRecord_start(pClientDlg->m_hRecHandle, 0x2, NULL);
AVRecord_sendOneFrame(pClientDlg->m_hRecHandle, frameData, frameLen);
pClientDlg->m_bRecording = TRUE;
pClientDlg->m_bRec = FALSE;
}
}
}
}
这些是VC定义:
typedef void far *LPVOID;
sprintf(定义)
#pragma warning(disable:4793)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_ARGLIST(int, __RETURN_POLICY_SAME, _CRTIMP, sprintf, vsprintf, __out_z char, _Dest, __in_z __format_string const char *, _Format)
这些是调用VC的DLL:
PLAYSDK_API int WINAPI PlaySDK_SendOneFrame(HANDLE hPlayHandle, unsigned char *frameBuf, int frameLen);
AVRECORD_API void WINAPI AVRecord_sendOneFrame(HANDLE handle, void *data, unsigned long datalen);
AVRECORD_API void WINAPI AVRecord_setVideoFormat(HANDLE handle,unsigned short codec_id, unsigned long width, unsigned long height,unsigned short frameRate);
AVRECORD_API void WINAPI AVRecord_setAudioFormat(HANDLE handle,unsigned short codec_id, unsigned short channels, unsigned short sampleRate, unsigned short bitsPerSample, unsigned short bitRate);
AVRECORD_API void WINAPI AVRecord_setCallBackFun(HANDLE handle,DataStreamCallBack pFun, void *context, WORD nchannel);
AVRECORD_API int WINAPI AVRecord_setRecordFileName(HANDLE handle, const char *fileName);
AVRECORD_API BOOL WINAPI AVRecord_start(HANDLE handle, int recordFlag, BtlFileDate *tBtlFileDate);
AVRECORD_API void WINAPI AVRecord_sendOneFrame(HANDLE handle, void *data, unsigned long datalen);
这个回调函数,我现在要用C#实现,可我对VC一点都不会,特别是指针,不知道怎么去用C#实现
希望那位高手能帮我实现,非常谢谢!
------解决方案--------------------自己去查数据类型对照,unsigned char *这个可以用string代替,如果是结构体指针,可以用ref 结构体实例 来表示
------解决方案--------------------其实C#调用C++ 的DLL文件很简单,首先自己建立一个专门用于调用dll文件接口函数的一个类,然后把System.Runtime.InteropServices;命名空间添加到类中,然后按照
[DllImport("DSCAMSDK.dll", EntryPoint = "CameraInit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern tagDS_CAMERA_STATUS CameraInit(dllfun_DS_SNAP_pROC pCallbackFunction, tagDS_RESOLUTION uiResolution, IntPtr hWndDisplay, UInt32 lpT