線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1807
推到 Plurk!
推到 Facebook!

請問有關於回傳值double* 的問題?

答題得分者是:aftcast
l90425
初階會員


發表:95
回覆:152
積分:49
註冊:2008-04-03

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-11-26 10:46:15 IP:59.125.xxx.xxx 訂閱
請問要如何將 double* 轉成 AnsiString 呢?
因為Edit2->Text=cc; 要轉成AnsiString才不會出錯!
或是建議要怎麼寫才比較好也都可以。
謝謝!謝謝!


[code cpp]
void __fastcall TForm1::Button1Click(TObject *Sender)
{
double b[4]={0};
HINSTANCE dllInstance = LoadLibrary("pdll.dll");
(FARPROC &)ShowCompute = GetProcAddress( dllInstance, "ShowCompute");
double* cc=ShowCompute(10,10,10,10,10,10,10,b);
Edit2->Text=cc; //這裡有問題
*cc ;
Edit3->Text=cc; //這裡有問題
FreeLibrary(dllInstance);
}

[/code]


pdll.dll
[code cpp]
double* __stdcall ShowCompute(double mainvf,double mainvm,double mainef,double mainem,double maingf,double maingm,double mainv12,double a[])
{
a[0]=Element1Compute(mainvf,mainvm,mainef,mainem);
a[1]=Element2Compute(mainvf,mainvm,mainef,mainem);
a[2]=G12Compute(maingf,maingm,mainvf,mainvm);
a[3]=PoissonV12Compute(mainv12);
return a;
}

[/code]
------
-謝謝大大熱心的回覆!謝謝!
編輯記錄
l90425 重新編輯於 2008-11-26 10:47:16, 註解 無‧
l90425 重新編輯於 2008-11-26 10:57:35, 註解 無‧
l90425 重新編輯於 2008-11-26 10:57:52, 註解 無‧
l90425 重新編輯於 2008-11-26 11:11:57, 註解 無‧
l90425 重新編輯於 2008-11-26 11:12:17, 註解 無‧
l90425 重新編輯於 2008-11-26 22:02:56, 註解 無‧
aftcast
站務副站長


發表:81
回覆:1485
積分:1763
註冊:2002-11-21

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-11-26 14:39:53 IP:122.120.xxx.xxx 訂閱
Edit2->Text= AnsiString(*cc);
------


蕭沖
--All ideas are worthless unless implemented--

C++ Builder Delphi Taiwan G+ 社群
http://bit.ly/cbtaiwan
編輯記錄
aftcast 重新編輯於 2008-11-26 14:41:47, 註解 無‧
l90425
初階會員


發表:95
回覆:152
積分:49
註冊:2008-04-03

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-11-26 16:46:34 IP:59.125.xxx.xxx 訂閱
如果使用AnsiString方法會使得原本的CC陣列{200,0.5,0.5,100}Edit2應該要顯示為200,而Edit3應該要顯示為0.5
卻變成了,Edit2顯示為200而Edit3顯示為2.8953428638726E-305

請問這有什麼方法解決嗎?
謝謝!
謝謝!

===================引 用 aftcast 文 章===================
Edit2->Text= AnsiString(*cc);
------
-謝謝大大熱心的回覆!謝謝!
aftcast
站務副站長


發表:81
回覆:1485
積分:1763
註冊:2002-11-21

發送簡訊給我
#4 引用回覆 回覆 發表時間:2008-11-26 17:17:00 IP:60.248.xxx.xxx 訂閱
  1. Edit2->Text=AnsiString(cc[0]);
  2. Edit3->Text=AnsiString(cc[1]);
這樣子還會錯嗎?


------


蕭沖
--All ideas are worthless unless implemented--

C++ Builder Delphi Taiwan G+ 社群
http://bit.ly/cbtaiwan
l90425
初階會員


發表:95
回覆:152
積分:49
註冊:2008-04-03

發送簡訊給我
#5 引用回覆 回覆 發表時間:2008-11-26 17:54:55 IP:59.125.xxx.xxx 訂閱
還是一樣也,實在不知道是為什麼會這樣呀!
謝謝!謝謝!
===================引 用 aftcast 文 章===================
  1. Edit2->Text=AnsiString(cc[0]);
  2. Edit3->Text=AnsiString(cc[1]);
這樣子還會錯嗎?


------
-謝謝大大熱心的回覆!謝謝!
aftcast
站務副站長


發表:81
回覆:1485
積分:1763
註冊:2002-11-21

發送簡訊給我
#6 引用回覆 回覆 發表時間:2008-11-26 18:11:32 IP:60.248.xxx.xxx 訂閱
看來不是AnsiString和double轉換的問題!  是否有debug過cc裡的值? 傳回來時是正確的嗎?
  1. Edit2->Text=AnsiString(b[0]);
  2. Edit3->Text=AnsiString(b[1]);

再者上面那樣也是造成有誤嗎?





------


蕭沖
--All ideas are worthless unless implemented--

C++ Builder Delphi Taiwan G+ 社群
http://bit.ly/cbtaiwan
l90425
初階會員


發表:95
回覆:152
積分:49
註冊:2008-04-03

發送簡訊給我
#7 引用回覆 回覆 發表時間:2008-11-26 18:49:59 IP:59.125.xxx.xxx 訂閱
也是會也!

[code cpp]
void __fastcall TForm1::Button1Click(TObject *Sender)
{
double b[4]={0};
HINSTANCE dllInstance = LoadLibrary("pdll.dll");
(FARPROC &)ShowCompute = GetProcAddress( dllInstance, "ShowCompute");
double* cc=ShowCompute(10,10,10,10,10,10,10,b);
double s1,s2,s3,s4;
s1=cc[0];
s2=cc[1];
s3=cc[2];
s4=cc[3];//執行到這裡時s1=200,
s2=0.5,s3=0.5,s4=10,
Label1->Caption=s1;//執行到這裡時數值卻變了s1=200,s2=0.500000000466484,s3=2.6361638597131E-308,s4=2.89534259373396E-305
Label2->Caption=s2;
Label3->Caption=s3;
}

[/code]

===================引 用 aftcast 文 章===================
看來不是AnsiString和double轉換的問題! 是否有debug過cc裡的值? 傳回來時是正確的嗎?
  1. Edit2->Text=AnsiString(b[0]);
  2. Edit3->Text=AnsiString(b[1]);

再者上面那樣也是造成有誤嗎?





------
-謝謝大大熱心的回覆!謝謝!
l90425
初階會員


發表:95
回覆:152
積分:49
註冊:2008-04-03

發送簡訊給我
#8 引用回覆 回覆 發表時間:2008-11-26 18:56:56 IP:59.125.xxx.xxx 訂閱

主程式
[code cpp]
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
double* (*ShowCompute)(double,double,double,double,double,double,double,double[]);
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
double b[4]={0};
HINSTANCE dllInstance = LoadLibrary("pdll.dll");
(FARPROC &)ShowCompute = GetProcAddress( dllInstance, "ShowCompute");
double* cc=ShowCompute(10,10,10,10,10,10,10,b);
double s1,s2,s3,s4;
s1=cc[0];
s2=cc[1];
s3=cc[2];
s4=cc[3];
Label1->Caption=s1;
Label2->Caption=s2;
Label3->Caption=s3;
}

[/code]

dll
[code cpp]
#include
#include
#pragma hdrstop
#pragma argsused
extern "C" __declspec(dllexport) double __stdcall Element1Compute(double,double,double,double);
extern "C" __declspec(dllexport) double __stdcall Element1Compute(double,double,double,double);
extern "C" __declspec(dllexport) double __stdcall G12Compute(double,double,double,double);
extern "C" __declspec(dllexport) double __stdcall PoissonV12Compute(double);
extern "C" __declspec(dllexport) double* __stdcall ShowCompute(double,double,double,double,double,double,double,double []);

USERES("pdll.res");
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved)
{
return 1;
}
//---------------------------------------------------------------------------
double __stdcall Element2Compute(double vf,double vm,double ef,double em)

{
double Anse2=0;
......
return Anse2;
}
double __stdcall Element1Compute(double vf,double vm,double ef,double em)
{
double Anse1=0;
......
return Anse1;
}
double __stdcall G12Compute(double gf,double gm,double vf,double vm)
{
double Ansg12=0;
......
return Ansg12;
}
double __stdcall PoissonV12Compute(double v12)
{
double Ansv12=0;
......
return Ansv12;
}
double* __stdcall ShowCompute(double mainvf,double mainvm,double mainef,double mainem,double maingf,double maingm,double mainv12,double a[])
{
a[0]=Element1Compute(mainvf,mainvm,mainef,mainem);
a[1]=Element2Compute(mainvf,mainvm,mainef,mainem);
a[2]=G12Compute(maingf,maingm,mainvf,mainvm);
a[3]=PoissonV12Compute(mainv12);
return a;
}

[/code]
------
-謝謝大大熱心的回覆!謝謝!
l90425
初階會員


發表:95
回覆:152
積分:49
註冊:2008-04-03

發送簡訊給我
#9 引用回覆 回覆 發表時間:2008-11-26 20:47:27 IP:59.125.xxx.xxx 訂閱
如果怎麼寫就能正常顯示了,但是希望大大能告訴我為什麼這麼寫就能了,因為我覺得怎麼寫跟上面的寫法沒有什麼太大的差別

謝謝!謝謝!
[code cpp]
double sd[4];
void __fastcall TForm1::Button3Click(TObject *Sender)
{
double b[4]={0};
HINSTANCE dllInstance = LoadLibrary("pdll.dll");
double* (*ShowCompute)(double,double,double,double,double,double,double,double[]);
(FARPROC &)ShowCompute = GetProcAddress( dllInstance, "ShowCompute");
double* cc=ShowCompute(10,10,10,10,10,10,10,b);
for(int i=0;i<4;i )
sd[i]=cc[i];
FreeLibrary(dllInstance);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
Edit1->Text=AnsiString(sd[0]);
Edit2->Text=AnsiString(sd[1]);
Edit3->Text=AnsiString(sd[2]);
Edit4->Text=AnsiString(sd[3]);
}

[/code]
------
-謝謝大大熱心的回覆!謝謝!
系統時間:2024-04-19 11:34:26
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!