請問有關於回傳值double* 的問題? |
答題得分者是:aftcast
|
l90425
初階會員 發表:95 回覆:152 積分:49 註冊:2008-04-03 發送簡訊給我 |
請問要如何將 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]
------
-謝謝大大熱心的回覆!謝謝! |
aftcast
站務副站長 發表:81 回覆:1485 積分:1763 註冊:2002-11-21 發送簡訊給我 |
|
l90425
初階會員 發表:95 回覆:152 積分:49 註冊:2008-04-03 發送簡訊給我 |
|
aftcast
站務副站長 發表:81 回覆:1485 積分:1763 註冊:2002-11-21 發送簡訊給我 |
|
l90425
初階會員 發表:95 回覆:152 積分:49 註冊:2008-04-03 發送簡訊給我 |
|
aftcast
站務副站長 發表:81 回覆:1485 積分:1763 註冊:2002-11-21 發送簡訊給我 |
|
l90425
初階會員 發表:95 回覆:152 積分:49 註冊:2008-04-03 發送簡訊給我 |
也是會也!
[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裡的值? 傳回來時是正確的嗎?
再者上面那樣也是造成有誤嗎?
------
-謝謝大大熱心的回覆!謝謝! |
l90425
初階會員 發表:95 回覆:152 積分:49 註冊:2008-04-03 發送簡訊給我 |
主程式 [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 發送簡訊給我 |
如果怎麼寫就能正常顯示了,但是希望大大能告訴我為什麼這麼寫就能了,因為我覺得怎麼寫跟上面的寫法沒有什麼太大的差別
謝謝!謝謝! [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]
------
-謝謝大大熱心的回覆!謝謝! |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |