Perl workshop in beijing

Now,the perl workshop in beijing is starting. 来自世界各国的朋友欢聚一堂,开始了perl的盛宴。

Categories

| | 评论(7)

评论(7)

您好!
很高兴能再perl大会上听到您的演讲,很遗憾由于有事没能和您当面交流。大会上您说的可以安排一个面试的机会,不知道现在和您联系可不可以。
我的MSN是lifuxue223521@hotmail.com
QQ是 236130132

期待您的消息,谢谢!

您好,可以的。
您感兴趣的话,可以先把简历发到我的邮箱 junliang.li#alibaba-inc.com。

我想问个问题,我想通过Win32::API来调用我的dll中的函数。如果参数是integer类型,能够正常调用,返回正确的计算结果。但是,如果参数是double类型,就会报错!
"Perl Command Line Interpreter has encountered a problem and needs to close. We are sorry for the inconvenience"
是不是Win32::API不支持double类型的参数?

#这个能正确调用
my $function=Win32::API->new('TestDLL', 'int foo1(int P, int T)');
my $return=$function->Call(100, 200);

#这个调用会出错
my $function2=Win32::API->new('TestDLL', 'double foo2(double P, double T)');
my $return2=$function2->Call(10.0, 20.0);

The third parameter, the input parameter list, specifies how many arguments the function wants, and their types. It can be passed as a single string, in which each character represents one parameter, or as a list reference. The following forms are valid:

"abcd"
[a, b, c, d]
\@LIST

But those are not:

(a, b, c, d)
@LIST

The number of characters, or elements in the list, specifies the number of parameters, and each character or element specifies the type of an argument; allowed types are:

I: value is an integer (int)
N: value is a number (long)
F: value is a floating point number (float)
D: value is a double precision number (double)
C: value is a char (char)
P: value is a pointer (to a string, structure, etc...)
S: value is a Win32::API::Struct object (see below)
K: value is a Win32::API::Callback object (see Win32::API::Callback)

Our function needs two parameters: a number (DWORD) and a pointer to a string (LPSTR):

$GetTempPath = new Win32::API('kernel32', 'GetTempPath', 'NP', ...

Then

The fourth and final parameter is the type of the value returned by the function. It can be one of the types seen above, plus another type named V (for void), used for functions that do not return a value. In our example the value returned by GetTempPath() is a DWORD, so our return type will be N:

$GetTempPath = new Win32::API('kernel32', 'GetTempPath', 'NP', 'N');

Now the line is complete, and the GetTempPath() API is ready to be used in Perl. Before calling it, you should test that $GetTempPath is defined, otherwise either the function or the library could not be loaded; in this case, $! will be set to the error message reported by Windows. Our definition, with error checking added, should then look like this:

$GetTempPath = new Win32::API('kernel32', 'GetTempPath', 'NP', 'N');
if(not defined $GetTempPath) {
die "Can't import API GetTempPath: $!\n";
}

I don't know if you can understood .

这个我看过,但是没能成功!我觉得Win32::API可能不支持double类型的参数和返回值。
你能不能试验确认一下?

刚刚测试《Perl高级编程(Profssional Perl Programming)》中的例子

use Win32::API;
# import the cos function
$cos = new Win32::API('msvcrt', 'cos', 'D', 'D');
# $cos is an object, use the Call() method on it
$result = $cos->Call(2.0);
print "cos(2.0) = $result\n";

仍然没有成功!你试一试,能不能行?

你那个测试提示什么错误?
我一般在linux下,现在没有windows平台。

发表评论

August 2012

      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

关于此日记

此日记由 Cnangel 发表于 September 19, 2009 3:34 PM

此Blog上的上一篇日记重回校园的感觉

此Blog上的下一篇日记感冒了

首页归档页可以看到最新的日记和所有日记。

归档

Powered by Movable Type 5.14-en