动态连接库中的Char *如何转换为Delphi中的相应类型?急急急!并不简单!(100分)

  • 主题发起人 主题发起人 bunker
  • 开始时间 开始时间
B

bunker

Unregistered / Unconfirmed
GUEST, unregistred user!
我使用北京赛维出的蓝星宝盒外置usb图像采集卡,使用它的sdk时的第一个驱动初始化函数
就调用不成功。。。他自带了一个vc的例子就可以,我不知错在那里,请大家务必帮忙!若能
帮助解决,分可以另加!拜托!拜托!
动态连接库的名称为udi.dll,
//udi.h 描述了udi.dll的函数
enum CaptureSessionType
{
SPE_CAPTURE,
LVE_CAPTURE,
ANY_CAPTURE
};
enum ZUDIMessage
{
ZUDI_OK,
ZUDI_WRONG_CAPTURE_TYPE,
ZUDI_VALUE_OUT_OF_RANGE,
ZUDI_UNKNOWN_PARAMETER,
ZUDI_DEVICE_NOT_ACTIVE,
ZUDI_DEVICE_OVERFLOW,
ZUDI_ILLEGAL_INPUT_PARAMETERS,
ZUDI_LACK_OF_INPUT_PARAMETERS,
ZUDI_OUT_OF_MEMORY,
ZUDI_INTERNAL_ERROR,
ZUDI_CORRUPT_AUDIO_STREAM,
ZUDI_OUT_OF_SYNC,
ZUDI_TIME_OUT,
ZUDI_ERROR_ACCESS_FILE,
ZUDI_VIEWER_ERROR,
ZUDI_DEVICE_IS_USED_BY_ANOTHER_APPLICATION,
ZUDI_PICTURE_FORMAT_PAL_DETECTED,
ZUDI_PICTURE_FORMAT_NTSC_DETECTED
};
enum UDIParams
{
CAPTURE_AUDIO_PARAM,
CAPTURE_VIDEO_PARAM,
SAVE_ELEMENTARY_STREAMS_PARAM,
SAVE_SYSTEM_STREAM_PARAM,
PICTURE_SIZE_PARAM,
PICTURE_FORMAT_PARAM,
VIDEO_BITRATE_PARAM,
PICTURE_QUALITY_PARAM,
BLANK_VCR_DISTORTION_PARAM,
VCD_FORMAT_PARAM,
BRIGHTNESS_PARAM,
CONTRAST_PARAM,
HUE_PARAM,
SATURATION_PARAM,
SYSTEM_STREAM_FILE_NAME_PARAM,
ELEMENTARY_VIDEO_STREAM_FILE_NAME_PARAM,
ELEMENTARY_AUDIO_STREAM_FILE_NAME_PARAM,
SPE_FILE_NAME_PARAM,
DRIVER_NAME_PARAM,
WINDOW_HANDLE_PARAM,
SET_FULL_SCREEN_PARAM,
CREATE_REPORT_FILE_PARAM,
ERROR_EVENTS_HANDLE,
ACTIVATE_VIEWER_PARAM,
CONFIGURE_VIDEO_DECODER_PARAM,
AUDIO_BITRATE_PARAM,
AUDIO_COMPRESSION_MODE_PARAM,
SET_WINDOW_TITLE_PARAM,
WINDOW_TITLE_PARAM,
SET_MESSAGE_DRAIN_PARAM,
SET_WINDOW_SIZE_PARAM,
DETECT_SCENE_CHANGE_PARAM,
NUMBER_OF_UDI_PARAMS // for counting only
};
//初始化函数
UDI_API ZUDIMessage ZUDISetParam(CaptureSessionType CaptureSession,
UDIParams ParameterName,
char *Value);

//sdk自带的vc例子片断,经编译后测试无误
//设定驱动名称
char *DRIVER_NAME="URANUSLT";
// Set the driver
ReturnedValue = ZUDISetParam(ANY_CAPTURE, DRIVER_NAME_PARAM, DRIVER_NAME);
if(ReturnedValue == ZUDI_OK)
{
// Get handles for SIF and QSIF windows for the viewer.
m_SIF_Window= ::GetDlgItem( m_hWnd, IDC_SIF_CUSTOM );
m_QSIF_Window= ::GetDlgItem( m_hWnd, IDC_QSIF_CUSTOM );
m_FULL_Window= ::GetDlgItem( m_hWnd, IDC_FULL_SCREEN_CUSTOM );
// Send Error handle
ReturnedValue = ZUDI_OK;//ZUDISetParam(ANY_CAPTURE, ERROR_EVENTS_HANDLE, (DWORD)m_ErrorEvent);
if(ReturnedValue == ZUDI_OK)
{
// Start capture - view not recording
ReturnedValue = ZUDISetParam(LVE_CAPTURE, WINDOW_HANDLE_PARAM, (DWORD)m_SIF_Window);
if(ReturnedValue == ZUDI_OK)
{
ZUDISetParam(LVE_CAPTURE, SET_FULL_SCREEN_PARAM, UDI_FALSE );
m_SubMenu->EnableMenuItem(IDR_RESIZE,MF_DISABLED | MF_GRAYED);
ReturnedValue = ZUDIStartCapture(LVE_CAPTURE);
m_ConfigureVDEC = FALSE;
// After first time,do
not configure it any more
}
}
。。。。。
以下是我的delphi程序,我先写了一个udi.pas,把udi,h的内容翻译过来,相关内容如下:
//udi.pas
interface
uses
Windows,
MMSystem,
Messages,
CommDlg;
type
CaptureSessionType=(
SPE_CAPTURE,
LVE_CAPTURE,
ANY_CAPTURE
);
type
ZUDIMessage=(
ZUDI_OK,
ZUDI_WRONG_CAPTURE_TYPE,
ZUDI_VALUE_OUT_OF_RANGE,
ZUDI_UNKNOWN_PARAMETER,
ZUDI_DEVICE_NOT_ACTIVE,
ZUDI_DEVICE_OVERFLOW,
ZUDI_ILLEGAL_INPUT_PARAMETERS,
ZUDI_LACK_OF_INPUT_PARAMETERS,
ZUDI_OUT_OF_MEMORY,
ZUDI_INTERNAL_ERROR,
ZUDI_CORRUPT_AUDIO_STREAM,
ZUDI_OUT_OF_SYNC,
ZUDI_TIME_OUT,
ZUDI_ERROR_ACCESS_FILE,
ZUDI_VIEWER_ERROR,
ZUDI_DEVICE_IS_USED_BY_ANOTHER_APPLICATION,
ZUDI_PICTURE_FORMAT_PAL_DETECTED,
ZUDI_PICTURE_FORMAT_NTSC_DETECTED
);
type
UDIParams=(
CAPTURE_AUDIO_PARAM,
CAPTURE_VIDEO_PARAM,
SAVE_ELEMENTARY_STREAMS_PARAM,
SAVE_SYSTEM_STREAM_PARAM,
PICTURE_SIZE_PARAM,
PICTURE_FORMAT_PARAM,
VIDEO_BITRATE_PARAM,
PICTURE_QUALITY_PARAM,
BLANK_VCR_DISTORTION_PARAM,
VCD_FORMAT_PARAM,
BRIGHTNESS_PARAM,
CONTRAST_PARAM,
HUE_PARAM,
SATURATION_PARAM,
SYSTEM_STREAM_FILE_NAME_PARAM,
ELEMENTARY_VIDEO_STREAM_FILE_NAME_PARAM,
ELEMENTARY_AUDIO_STREAM_FILE_NAME_PARAM,
SPE_FILE_NAME_PARAM,
DRIVER_NAME_PARAM,
WINDOW_HANDLE_PARAM,
SET_FULL_SCREEN_PARAM,
CREATE_REPORT_FILE_PARAM,
ERROR_EVENTS_HANDLE,
ACTIVATE_VIEWER_PARAM,
CONFIGURE_VIDEO_DECODER_PARAM,
AUDIO_BITRATE_PARAM,
AUDIO_COMPRESSION_MODE_PARAM,
SET_WINDOW_TITLE_PARAM,
WINDOW_TITLE_PARAM,
SET_MESSAGE_DRAIN_PARAM,
SET_WINDOW_SIZE_PARAM,
DETECT_SCENE_CHANGE_PARAM,
NUMBER_OF_UDI_PARAMS // for counting only
);
function ZUDISetParam(CaptureSession:CaptureSessionType;
ParameterName:UDIParams;
Value:PChar):ZUDIMessage;stdcall;
implementation

const
udidll='UDI.DLL';
function ZUDISetParam(CaptureSession:CaptureSessionType;
ParameterName:UDIParams;
Value:PChar):ZUDIMessage;stdcall;
external udidll name '?ZUDISetParam@@YA?AW4ZUDIMessage@@W4CaptureSessionType@@W4UDIParams@@PAG@Z';
以下是我的调用程序
//CaptureMPEG.pas
procedure TForm1.Button1Click(Sender: TObject);
var
ReturnedValue:ZUDIMessage;
DRIVER_NAME:array[0..8] of Char
tmp:string;
m_ConfigureVDEC:boolean;
begin

ReturnedValue:=ZUDI_OK;
//DRIVER_NAME:='URANUSLT';
tmp:='URANUSLT';
DRIVER_NAME[0]:='U';
DRIVER_NAME[1]:='R';
DRIVER_NAME[2]:='A';
DRIVER_NAME[3]:='N';
DRIVER_NAME[4]:='U';
DRIVER_NAME[5]:='S';
DRIVER_NAME[6]:='L';
DRIVER_NAME[7]:='T';
Driver_NAME[8]:=#0;
//pDriver:=@DRIVER_NAME;
//DRIVER_NAME:=@tmp;}

//StrPCopy(DRIVER_NAME,tmp);
if ReturnedValue=ZUDI_OK then

begin

//就是下面这一句,总是返回ZUDI_WRONG_CAPTURE_TYPE信息,而在vc中返回的是
//ZUDI_OK,我怀疑是DRIVER_NAME有问题,但不知如何传递这个PChar参数,我用PChar()
//,StrPCopy和Char数组都用过了。
ReturnedValue:=ZUDISetParam(ANY_CAPTURE,DRIVER_NAME_PARAM,DRIVER_NAME);
if ReturnedValue=ZUDI_OK then

begin

ReturnedValue := ZUDISetParamC(LVE_CAPTURE, WINDOW_HANDLE_PARAM, DWORD(Panel1.Handle));
if ReturnedValue=ZUDI_OK then

begin

ReturnedValue:=ZUDISetParamC(LVE_CAPTURE,SET_FULL_SCREEN_PARAM,DWORD(UDI_FALSE));
if ReturnedValue=ZUDI_OK then

begin

ReturnedValue:=ZUDIStartCapture(LVE_CAPTURE);
if ReturnedValue=ZUDI_OK then
showmessage('ok');
end;

end;

end;

end;

end;
 
Char * 就是Delphi的PChar
估计是调用方式问题,delphi的默认调用方式和vc不同。
是用stdcall还是用c方式,我一时想不起来,书在公司,呵呵,不好意思。 ;)
你可以一个个的测试,也不难 。 ;)
 
我stdcall,Cdecl都试过了,我也怀疑是调用方式不同,它的dll没有使用extern "C",其他
的我就不知道了。有调用过vc写的dll经验的朋友想想!
 
是我粗心大意,把name的值搞错了,dll中的ZUDISetParam有三种定义,参数类型不同。
多谢各位,给分
 
后退
顶部