- 论坛徽章:
- 0
|
我的dll头文件定义如下:
// MY_API.h
#ifndef __MYAPI_H_H_
#define __MYAPI_H_H_
#ifdef MY_EXPORTS
#define MY_API __declspec(dllexport)
#else
#define MY_API __declspec(dllimport)
#endif
MY_API float __stdcall add_f(float a, float b);
#endif //__MYAPI_H_H_
实现文件
// MY_API.cpp
#include "stdafx.h"
#include "MY_API.h"
MY_API float __stdcall add_f(float a, float b)
{
return (float)(a + b);
}
.def 文件
// MY_API.def
LIBRARY "MY_API"
EXPORTS
add_f
// perl 中调用此dll为:
#! /usr/bin/perl -w
use Win32::API;
$test_dll = 'E:\perl\MY_API.dll';
die "can't find MY_API.dll \n" unless -e $test_dll;
$add_f = new Win32::API($test_dll, "float add_f(float a, float b)");
if (not defined $add)
{
die "Can't import API add_f: $!\n";
}
$sum = 0.0;
$sum = $add_f->Call(3.2, 2.5); #执行此语句后程序崩溃,
#提示: Perl Command Interpreter has encountered a problem and needs to close.
#We are sorroy for the inconvenience.
print "$sum\n";
请高手指点指点啊,
如果把float 换成 int 的调用没有问题。
就是perl如果调用的dll中函数,如果函数含有float* 参数, 或者是返回float 类型的,调用就会出错。
谢谢帮忙啊。急急急。。。。 |
|