Home > Back-end >  Urgent ask for help, C builder to encapsulate DLL cannot perform functions normally
Urgent ask for help, C builder to encapsulate DLL cannot perform functions normally

Time:09-17

I made up a program function is: from D plate TXT file folder selected, and to merge files and data extraction,
Not encapsulated in the. DLL procedures before can run normally, encapsulation after finishing the following error message: access violation at address XXXXX xx. The module in a DLL, interface program there is no problem, you great god can provide the help you seek counsel, grateful
After the discovery of the error I step through pop-up place in edit1 display file name on this statement, the code is as follows:
_fastcall TForm1: : TForm1 (TComponent * Owner)
: TForm (the Owner)
{
Int row;
Int lines;
Const char * importFilePath;
The FILE * fp=NULL;
OpenDialog1 - & gt; InitialDir="D: \ ";
OpenDialog1 - & gt; The Filter="text file (*.txt) | *. TXT | all files (*. *) | *. *";
SaveDialog1 - & gt; InitialDir="D: \ ";
SaveDialog1 - & gt; The Filter="text file (*.txt) | *. TXT | all files (*. *) | *. *";
SaveDialog1 - & gt; DefaultExt=". TXT ";
OpenDialog2 - & gt; InitialDir="D: \ ";
OpenDialog2 - & gt; The Filter="text file (*.txt) | *. TXT | all files (*. *) | *. *";
SaveDialog2 - & gt; FileName="SwarmUUV";
SaveDialog2 - & gt; InitialDir="D: \ ";
SaveDialog2 - & gt; The Filter="text file (*.txt) | *. TXT | all files (*. *) | *. *";
SaveDialog2 - & gt; DefaultExt=". TXT ";
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Void __fastcall TForm1: : ImportFileButtonClick (TObject * Sender)
{
OpenDialog1 - & gt; The Execute ();
Form1 - & gt; Edit1 - & gt; Text=Form1 - & gt; OpenDialog1 - & gt; The FileName.
}

CodePudding user response:

error message and not the normal procedures before packaging

CodePudding user response:

In the context of the code, there should be no problem, although
OpenDialog1 - & gt; The Execute ();
Form1 - & gt; Edit1 - & gt; Text=Form1 - & gt; OpenDialog1 - & gt; The FileName.
Logic is a little problem, it should be
If (OpenDialog1 - & gt; The Execute ())
Form1 - & gt; Edit1 - & gt; Text=Form1 - & gt; OpenDialog1 - & gt; The FileName.
But will not lead to abnormal

CodePudding user response:

Form1 to this?

CodePudding user response:

You put the project name. Look CPP files posted?

CodePudding user response:

reference ooolinux reply: 3/f
Form1 to this?
thank you very much, have normal operation, but the principle I don't know, could you tell me, thank you very much

CodePudding user response:

Thank you great god help, has solved the problem, will change Form1 pointer to this

CodePudding user response:

reference 5 floor qq_43231268 reply:
Quote: refer to the third floor ooolinux response:

Form1 to this?
thank you very much, have normal operation, the principle of but I'm not sure, could you tell me, thank you very much


Use this is a c + + standard syntax, and Form1 is a global variable name (external), have the scope and effectiveness problems (such as whether to NULL or not created), specific principles say not clear, if is AV error Form1 is NULL,
High version of the compiler doesn't seem to support some Form1 - & gt; Edit1,

CodePudding user response:

Your DLL output interface function, use new to dynamically create TForm1 form? This time no Form1 what happened, Form1 or NULL,
Exe inside with Form1 normal because of the project:
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 

#include
# pragma hdrstop
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
USEFORM (" Unit1. CPP, "Form1);
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int)
{
Try
{
Application - & gt; The Initialize ();
Application - & gt; CreateForm (__classid (TForm1), & amp; Form1);//created Form1 form here, is not new to create
Application - & gt; The Run ();
}
The catch (Exception & amp; The exception)
{
Application - & gt; ShowException (& amp; The exception);
}
The catch (... )
{
Try
{
Throw Exception (" ");
}
The catch (Exception & amp; The exception)
{
Application - & gt; ShowException (& amp; The exception);
}
}
return 0;
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

CodePudding user response:

In internal use Form1 TFrom1 member function is actually redundant
Form1 - & gt; Edit1 - & gt; Text=Form1 - & gt; OpenDialog1 - & gt; The FileName.
Can
Edit1 - & gt; Text=OpenDialog1 - & gt; The FileName.

CodePudding user response:

refer to the eighth floor ooolinux response:
your DLL output interface function, use new to dynamically create TForm1 form? This time no Form1 what happened, Form1 or NULL,
Exe inside with Form1 normal because of the project:
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 

#include
# pragma hdrstop
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
USEFORM (" Unit1. CPP, "Form1);
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int)
{
Try
{
Application - & gt; The Initialize ();
Application - & gt; CreateForm (__classid (TForm1), & amp; Form1);//created Form1 form here, is not new to create
Application - & gt; The Run ();
}
The catch (Exception & amp; The exception)
{
Application - & gt; ShowException (& amp; The exception);
}
The catch (... )
{
Try
{
Throw Exception (" ");
}
The catch (Exception & amp; The exception)
{
Application - & gt; ShowException (& amp; The exception);
}
}
return 0;
}
nullnullnullnullnullnullnullnullnullnullnullnull
  • Related