|
wwwrabbit1 already knows how to do that but wanted another way (to pass information to CView object) to accomplish the same thing and that is what the hint parameters are for.
I personaly would contenue to store the information in the document, where it (probably) belongs.
What we do not know is what effect the information is supposed to have, other than they effect what is to be shown.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Hello!
I'm currently writing some application, that contains a class A. It loads a DLL and passes a pointer to A to the DLL. The DLL includes the header file of A.
Anyway, when I try to compile this, I get LNK2001: unresolved external symbol errors for all A class function calls...
When I include all *.obj files as library files in the DLL settings, it compiles. But it doesn't really execute the actual functions of the main application then, it just compiles the whole code again into the DLL. It shouldn't do this, it should just call the real functions of the main application.
What must I do that the DLL can execute the functions of A?
Thanks and best regards,
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
write 0xAD to port 0x64
oh wait...
pass a pointer to the function to the DLL.
I know of no "reverse export" mechanism.
we are here to help each other get through this thing, whatever it is Vonnegut jr. boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
So it's impossible? Isn't there some possibility of generating a .lib file of main app or something like that?
How can I write a plugin architecture then? The DLL must be somehow be able to execute class functions of the main app...
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
Wooo! It is more than possible! The person who has the information at the tip of his tong is just not online. If we have not done anything like that in a while, then we have to try to remember enough to figure it out (if we have the time to go through the trouble).
There are articles at CP on plugins, DLLs and COMM (also in the MSDN Library).
When I first read your post (ealier today) the first thing I thought about was callback functions, but that was not what you where asking about. If you can pass a callback function you can pass a class pointer. Heck we pass class pointers and references to DLLs all the time, otherwise we could not use MFC.
Your question is resonable and someone may yet answer it.
I am no expert on DLLs, so I did not try to figure out what the problem was.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
The person who has the information at the tip of his tong is just not online.
Let's hope he'll get online soon
There are articles at CP on plugins, DLLs and COMM (also in the MSDN Library).
I've read most of them, but actually many of them are for C# only and the others for C++ never have the problem that the DLL wants to call something that is in the EXE. They'll just describe how to load and call a DLL, the DLL then does many things, like creating new windows, sending windows messages, etc. but never calls something of the EXE...
Thanks and best regards,
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
I have looked into this quite some time back and I'm afraid I can't remember what the outcome was, but I vaguely recall it was possible. You need to create a lib for the .exe and use that in the DLL. Also declare the functions as exported.
One issue that comes to mind though is DLL's are (can be) shared by .EXE's so which EXE would the exported function be in. I guess this info lives in the export information.
Another way to do this is for the .EXE to expose an array of functions DLL's can call. You could do this with delegates and probably signals and slots. Have a look at the truly excellent FastDelegate here on CP.
In my programmers editor (see sig) I enabled interpreted C functions to call C/C++ functions in my .EXE. This is done by my C compiler resolving function addresses via. the .EXE's MAP file. This works very well and allows extensions to the editor to do most anything that the .exe can.
Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
|
|
|
|
|
Also declare the functions as exported.
Doh I've searched the whole IDE, all subdialogs, etc. at least 2 hours for a setting to generate a .lib of the .exe file... Didn't find anything. I have almost given it up and then just prefixed some of the functions with __declspec(dllexport). Compiled it, and think what? It generated the .lib, .exp and exported the functions very nicely as one could see in the Dependency Viewer. Yay!!!
Added the .lib to the test plugin project (the DLL), compiled it, and everything works!!
Many many thanks!!!
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
:-DNot bad at all! An expert did not show up but someone who could get you looking in the right direction did. It never occured to me that you were not using export.
:(Now if I can just understand how to do basicaly the same thing via COM thru the IUnknow interface. Thats what I've been working on.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
John R. Shaw wrote:
Not bad at all! An expert did not show up but someone who could get you looking in the right direction did.
Hey who said I'm not an expert.
Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
|
|
|
|
|
Neville Franks wrote:
Hey who said I'm not an expert.
You know what I mean!
Some one who writes DLLs all the time and can answer questions about them in his sleep. By that deffinition most of us are not experts on DLLs.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Dominik Reichl wrote:
Added the .lib to the test plugin project (the DLL), compiled it, and everything works!!
Many many thanks!!!
Glad to be of help.
Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
|
|
|
|
|
Well, the most simple way is to move all 'exported' functionality (i.e. that part of the application the plugins should be able to access) into a separate dll itself. Plugins then just need to link to that dll in order to use them, as does the main application. (This would most likely be done via implicit linkage)
That way you also have enforced a modular concept for your application, which I'd recommend anyway as soon as your appication gets complex.
Many of my bigger projects evolved to a main exe that only served as 'launcher' for the dlls that contain the 'real application'.
Hope that helps,
Nick
|
|
|
|
|
I have a proyect in VC++6, and everytime I change ONE file, when I run the proyect, it asks me If I want to compile all the files in the proyect. If I choose 'No' , the changes I made in that file are not compiled (and linked) in the exe.
If I manually compile every modified file, the problem is that its not linked again (so, I have a new .obj, but the .exe is old).
Obviously, if i choose 'Yes' when it asks me, I have no problems, but it compiles the entire proyect every time I modify 1 file...!!
Please Help me!!
Thanks in advance
|
|
|
|
|
VC++ 6 by default only compiles the files affected by the change, unless you have manualy set to up to do otherwise.
(F7 or Build in menu): Compiles (affected files) and Links (Links entire project).
Unless that 1 file is a header that is used in every file, then the whole project should not be being recompiled. But the whole project will be relinked.
If you do not see in the build window
Compiling...
StdAfx.cpp
...
then it is not recompiling the whole project.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
|
Thanks for your answers!! That solved my problem... one of the computers had 2006 in the year configuration...!
I was wasting a lot of time compiling all the files (about 50) everytime I modified one of them... Thanks again!
|
|
|
|
|
Hi,
I have the function defined below, returns Ip without any error:
[code]
double Integral(void)
double j0,j1,H0,H1,p,Ip;
double bessj0(double x);
double bessj1(double x);
int t = 1;
alpha = beta = 2*t*PI; // t = 1
p = sqrt(pow(alpha,2.0)+pow(beta,2.0));
j0 = bessj0(2.0*p);
j1 = bessj1(2.0*p);
H0 = sum0(2.0*p);
H1 = sum1(2.0*p);
Ip = ((PI*p)/2) * ((2*p*j0) + (((PI*p)/2) * ((H0*j1)-(H1*j0))) - j1);
return Ip;
//}
}[/code]
However, I need an array, Ip[] to be returned;
not just one value. I made the following modifications to the code:
[code]
double Integrals(void)
{ double alpha[20],beta[20];
for (int t=1;t<21;t++)
{
double j0[20],j1[20],H0[20],H1[20],p[20],Ip[20];
double bessj0(double x[20]);
double bessj1(double x[20]);
int t = 1;
alpha[t] = beta[t] = 2*t*PI; // t = 1
p[t] = sqrt(pow(alpha[t],2.0)+pow(beta[t],2.0))
+sqrt(pow(alpha[t],2.0)+pow(beta[t],2.0));
j0[t] = bessj0(p[t]);
j1[t] = bessj1(p[t]);
H0[t] = sum0(p[t]);
H1[t] = sum1(p[t]);
Ip[t] = ((PI*p[t])/2) * ((2*p[t]*j0[t]) + (((PI*p[t])/2) * ((H0[t]*j1[t])-(H1[t]*j0[t]))) - j1[t]);
return Ip[20];
//}
}
}[/code]
However, I have 2 errors:
[code]error C2664: 'bessj0','bessj1' : cannot convert parameter 1 from 'double' to 'double []'[/code]
despite having modified the function definitions double bessj0(double x); and double bessj1(double x); to double bessj0(double x[20]); and double bessj1(double x[20]); WITHOUT ANY ERRORS.
viz:
[code]
double bessj0(double x)
//Returns the Bessel function j0(x) for any real x.
{
float x;
double ax,z,xx,y,ans1,ans2,j0;
if ((ax=fabs(x))<8.0) //Direct rational function fit
{
y=x*x;
ans1=57568490574.0+y*(-13362590354.0+y*(651619640.7
+y*(-11214424.18+y*(77392.33017+y*(-184.9052456)))));
ans2=57568490411.0+y*(1029532985.0+y*(9494680.718
+y*(59272.64853+y*(267.8532712+y*1.0))));
j0=ans1/ans2;
}
else
{
z=8.0/ax;
y=z*z;
xx=ax-0.785398164;
ans1=1.0+y*(-0.1098628627e-2+y*(0.2734510407e-4
+y*(-0.2073370639e-5+y*0.2093387211e-6)));
ans2=-0.1562499995e-1+y*(0.1430488765e-3
+y*(-0.6911147651e-5+y*(0.7621095161e-6
-y*0.934945152e-7)));
j0=sqrt(0.636619772/ax)*(cos(xx)*ans1-z*sin(xx)*ans2);
}
return j0;
}[/code]
to:
[code]
double bessj0(double x[20])
//Returns the Bessel function j0(x) for any real x.
{
double ax[20],z[20],xx[20],y[20],ans1[20],ans2[20],j0[20];
if ((ax[20]=fabs(x[20]))<8.0) //Direct rational function fit
{
y[20]=x[20]*x[20];
ans1[20]=57568490574.0+y[20]*(-13362590354.0+y[20]*(651619640.7
+y[20]*(-11214424.18+y[20]*(77392.33017+y[20]*(-184.9052456)))));
ans2[20]=57568490411.0+y[20]*(1029532985.0+y[20]*(9494680.718
+y[20]*(59272.64853+y[20]*(267.8532712+y[20]*1.0))));
j0[20]=ans1[20]/ans2[20];
}
else
{
z[20]=8.0/ax[20];
y[20]=z[20]*z[20];
xx[20]=ax[20]-0.785398164;
ans1[20]=1.0+y[20]*(-0.1098628627e-2+y[20]*(0.2734510407e-4
+y[20]*(-0.2073370639e-5+y[20]*0.2093387211e-6)));
ans2[20]=-0.1562499995e-1+y[20]*(0.1430488765e-3
+y[20]*(-0.6911147651e-5+y[20]*(0.7621095161e-6
-y[20]*0.934945152e-7)));
j0[20]=sqrt(0.636619772/ax[20])*(cos(xx[20])*ans1[20]-z[20]*sin(xx[20])*ans2[20]);
}
return j0[20];
}[/code]
Is there another way I can re-write the code such that I return THE ARRAY, Ip[]? from the function double Integrals(void)?
THANKS
|
|
|
|
|
If this is a C++ program rather than C, use a vector (or CArray for MFC) rather than an array and return that. Otherwise return the array via a function argument.
Kevin
|
|
|
|
|
Thanks Kevin.
It is a Visual C++ project, w/ MFC. How would I implement your modification in my code already pasted?
|
|
|
|
|
Actually the easiest way to do what you want is just to pass Ip[] as a function argument, e.g.,
void Integrals(double Ip[])
Before you call the function you should initialise the array like this.
double Ip[20] = {0.0}; // set 20 values to 0.0
Then call like
Integrals(Ip);
You probably also want to specify the size of the array as an argument
void Integrals(const int max_size, double Ip[])
and then use that for your loop and array bounds.
Basically your 20 should be replaced by a constant declaration.
Kevin
|
|
|
|
|
You could use a vector or just plain old array.
double* MyFunc()
{
double* pd = new double(SIZE OF ARRAY);
return db;
}
void MyOtherFunc()
{
double* pd = MyFunc();
delete dp;
}
Good Luck!
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Thanks for the valuable tips!
Since I'd rather not mess with pointers if I can help it, I called the array in my Bessel functions; viz:
void bessj0(double x[20],double j0[20])
{
double ax[20],z[20],xx[20],y[20],ans1[20],ans2[20];
for (int i=0;i<20;i++)
{
if ((ax[i]=fabs(x[i]))<8.0)
{
y[i]=x[i]*x[i];
ans1[i]=57568490574.0+y[i]*(-13362590354.0+y[i]*(651619640.7
+y[i]*(-11214424.18+y[i]*(77392.33017+y[i]*(-184.9052456)))));
ans2[i]=57568490411.0+y[i]*(1029532985.0+y[i]*(9494680.718
+y[i]*(59272.64853+y[i]*(267.8532712+y[i]*1.0))));
j0[i]=ans1[i]/ans2[i];
}
else
{
z[i]=8.0/ax[i];
y[i]=z[i]*z[i];
xx[i]=ax[i]-0.785398164;
ans1[i]=1.0+y[i]*(-0.1098628627e-2+y[i]*(0.2734510407e-4
+y[i]*(-0.2073370639e-5+y[i]*0.2093387211e-6)));
ans2[i]=-0.1562499995e-1+y[i]*(0.1430488765e-3
+y[i]*(-0.6911147651e-5+y[i]*(0.7621095161e-6
-y[i]*0.934945152e-7)));
j0[i]=sqrt(0.636619772/ax[i])*(cos(xx[i])*ans1[i]-z[i]*sin(xx[i])*ans2[i]);
}
}
}
I later called the function above with:
bessj0(p,j0);
But I'm not sure if a certain line in the implementing code, to return Ip[] would be valid, viz:
void Integrals(double Ip[20])
{
double alpha[20],beta[20];
for (int t=0;t<20;t++)
{
double j0[20],j1[20],H0[20],H1[20],p[20];
void bessj0(double x[20],double j0[20]);
void bessj1(double x[20],double j1[20]);
alpha[t] = beta[t] = 2*t*PI;
p[t] = 2*sqrt(pow(alpha[t],2.0)+pow(beta[t],2.0));
bessj0(p,j0);
bessj1(p,j1);
H0[t] = sum0(p[t]);
H1[t] = sum1(p[t]);
Ip[t] = ((PI*p[t])/2) * ((2*p[t]*j0[t]) + (((PI*p[t])/2) * ((H0[t]*j1[t])-(H1[t]*j0[t]))) - j1[t]);
}
}
Also, why didn't I get an error at line (***)? The function is defined thus:
double sum0(double x)
{
double H0;
H0 = x - (pow(x,3)/9) + (pow(x,5)/(9*25)) - (pow(x,7)/(9*25*49))
+ (pow(x,9)/(9*25*49*81)) - (pow(x,11)/(9*25*49*81*121));
return H0;
}
The code pasted compiles without any errors. But I'm concerned to make sure I'm doing the correct and logical thing in the 1st place.
I'd be greatful for constructive criticism and useful tips directly applicable to the pasted code. Thanks a lot!
|
|
|
|
|
If you are going to pass arrays then it is best to pass them as a pointer to array.
void Integrals(double Ip[20])
{
....
for( i=0; i<20; ++i )
Ip[i] = what ever;
}
void Integrals(double *Ip)
{
....
for( i=0; i<20; ++i )
Ip[i] = what ever;
}
void Integrals(double *Ip, int nSize)
{
....
for( i=0; i<nSize; ++i )
Ip[i] = what ever;
}
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Hi,
I've got a problem with the IShellFolder2 interface...
I want to use its GetDetailsEx funtion in a file tree application...
I add an interface pointer to my class and add a relese funtion for it in the destructor.
But when i compile the code VC++ gives me the following errors:
h:\Mydoc\C++\Visual Studio Projects\Lars\TreeNode.cpp(11) : error C2027: use of undefined type 'IShellFolder2'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\ShObjIdl.h(83) : see declaration of 'IShellFolder2'
h:\Mydoc\C++\Visual Studio Projects\Lars\TreeNode.cpp(11) : error C2227: left of '->Release' must point to class/struct/union
I've tried to move the code into a seperate file but still gets the same error..
I've no idea what can be wrong... Do I have to import something that implement the interface?
Thanks....
|
|
|
|
|