我们知道pb中不支持指针,但我们在使用WIN32 API和调用一些dll中的外部函数时候,经常会与其打些交道,所以这里将相关的一些技巧收集整理起来。
1、根据字符串地址得到字符串
完全通过pb自带的函数String就可以实现,函数的语法为String ( data, { format } ),当我们将变量地址作为Data参数,字符串“Address”作为format参数,函数的返回值就是我们需要的字符串。这是种未公开(呵呵,pb的帮助中找不到),但被广泛使用的方法。
例:string ls_tmp
ls_tmp =string(hStrData,"Address")
2、得到pb中某个字符串变量的地址
这次,单纯依靠pb自身是行不通了,需要请来Win Api函数帮忙了:
主人公:Function long lstrcpy(ref string Destination, ref string Source) library "kernel32.dll"
原型:
The lstrcpy function copies a string to a buffer.
LPTSTR lstrcpy(
LPTSTR lpString1, // address of buffer
LPCTSTR lpString2 // address of string to copy
);
Return Values:If the function succeeds, the return value is a pointer to the buffer.
看我怎么大显身手:
定义实例变量:String is_dst
string ls_src
long ll_address
ls_src= "test me"
ls_dst =space(255)
ll_address=lstrcpy(ls_dst,ls_src)
麻烦是麻烦点,不过终于知道你藏身在ll_address那里了。






