将CSring指针作为dll函数参数传递 [英] Passing CSring pointer as dll function argument

查看:136
本文介绍了将CSring指针作为dll函数参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我花了最后45天来处理dll,在大型项目管理中我得到了dll的很多好处.
以及每2个小时我都会遇到一个新的里程碑问题.

-------------------------------------------------- ------------------------------
问题:-
我将dll函数与 _descpsec(dllexport)配合使用,
现在让我们考虑以下场景,

名为 TwoString() 的普通dll函数,用于填充dll中的字符串.

Hi All,
I spend Last 45 days to deal with dll i got lots of advantages of dll for my big project management.
As Well as in every 2 Hours I got new milestone problem.

--------------------------------------------------------------------------------
Problem :-
I used dll function with _descpsec(dllexport)Which work greate,
Now lets consider following scenerio,

A function called TwoString()Normal dll function that fill strings in dll.

extern "C" __descspec(dllexport)void WINAPI TwoString(CString* First,CString* Second)
{
   Cstring tempstr,tempstr1;
   tempstr="SANTOSH";
   First=&tempstr;
   tempstr1="DHANAWADE";
   Second=&tempstr1;
}


此dll函数现在可以很好地运行了,
当我将指针作为函数参数传递时,必须更新该指针的字符串.

让我们进行以下函数调用


This dll function works greate now,
As i passed the pointer as function argument then string of that pointer must be updated.

Lets take following function call

CString Name,Surname;
Name="";
Surname="";
TwoString(&Name,&Surname);



正如我所说,在调用DLL之后,名称和姓氏的值应更改.

但未更改.
我尝试了:
1)我不希望实现返回值的结构或StringArray.
2)函数只能返回一个值.
3)当我调试名称和姓氏的程序指针时,直到l
First=&tempstr;
声明.
____________________________________________________________________
欢迎所有相关的帮助,链接,代码块,建议.



As I thing values of Name and Surname should change after DLL Called.

but Not Changed.
I have try:
1)I doesn''t want implement structure or StringArray for return value.
2)Function can return only one values.
3)When i debug program pointers of Name And Surname not changed untill
First=&tempstr;
Statement.
____________________________________________________________________
All related helps,Links,codeblocks,suggestions are welcome.

推荐答案

Try(即删除运算符的地址):
Try (i.e remove the addressof operators):
Cstring tempstr,tempstr1;
tempstr = "SANTOSH";
*First = tempstr;
tempstr1 = "DHANAWADE";
*Second = tempstr1;


或者使用引用而不是指针.

[edit]添加了Carlo的修复程序.[/edit]


Alternatively use references rather than pointers.

[edit]Added Carlo''s fixes.[/edit]


*First = "SANTOSH";
*Second = "DHANAWADE";


这篇关于将CSring指针作为dll函数参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆