|
I try to pass object to dll but I got access violation:
in cpp
TImage* newimage = new TImage(this);
typedef void(* __stdcall pPrint )( TImage* );
.......................................
Print ( newimage );
delete newimage;
in dll
extern "C" void __declspec (dllexport) __stdcall Print ( TImage* newimage )
{
newimage->Picture->LoadFromFile( "picture.bmp" );
}
Can anyone explain to me what I do wrong?
|
|
|
|
|
You export a non-static member of an object? Did you have a look at this -pointer of CDefExportedApp ? It is 0! You should at least tell the poor beginners why this crashes when trying to access a member of CDefExportedApp !
|
|
|
|
|
Hi Mahmood, I am Ajit.
I really learn quickly how to interact with DLLs.It helped me to get good start.
Thank you.
Ajit
|
|
|
|
|
Thanx, Goodluck Ajit
|
|
|
|
|
Hi All,
Could someone pls help me get this error out... I'm unable to declare the function with a vector type.
//errors
creepdll.h expected `;' before '(' token
creep.cpp no `double Creep::GetEvent(std::vector<double, std::allocator<double=""> >, int)' member function declared in class `Creep'
[creep.o] Error 1
// Original code
// Creepdll.h
//#define DLLEXPORT __declspec(dllexport)
class Creep
{
public:
__declspec(dllexport)double GetEvent(vector<double> event, int value);
};
// compile with: /EHsc /LD
#include "creepdll.h"
#include <iostream>
#include <stdexcept>
#include <vector> // Header for vector class
using namespace std;
double Creep::GetEvent(vector<double> press, int number_to_sum)
{
double presspress = 0.0;
return presspress;
}
//Main .exe
#include <cstdlib>
#include <iostream>
#include "creepdll.h"
#include <vector> // Header for vector class
using namespace std;
int main(void)
{
Creep a;
a.GetEvent();
system("PAUSE");
return 0;
}
Gee
|
|
|
|
|
Your problem is that you need to export your class or put your function outside a class.
Best wishes, C
|
|
|
|
|
When try to use the function the app crash! I don't know why. And yes maybe it's a good article, but it's like the help in VisStudio (2005 but in all). It' just not enoughtly detailed! Ex. Where to put the code??? In my case, couse I'm used C++ all in my life. I can find out. (shirimasen ) But for those who is new to C++ and VC++ it will be a pain anyway.
|
|
|
|
|
have you given the full path in LoadLibrary ,
Anurag chaudhary
Gurgaon
Haryana
|
|
|
|
|
Any more help on this topic? I am having the same problem:
typedef int (CALLBACK *PC_DLL_SHUTDWN)(void);
main() {
dllHandle = LoadLibrary("C:\\views\\pc\\AppDll\\Debug\\PcAppDll.dll");
if (dllHandle == NULL)
exit(1);
// dllHandle = 0x10000000 doesn't look right does it?
//Get pointer to our function using GetProcAddress:
PcDllShutdownPtr = (PC_DLL_SHUTDWN)GetProcAddress(dllHandle,
"PcDllShutdown");
// PcDllShutdownPtr is NULL; what do you think????
}
gdog
|
|
|
|
|
Wrote codes for MFCAppWizard(dll). Can't figure out where in files to place codes for the MFCAppWizard(exe).
codes:
typedef int (CALLBACK* LPFNMLTPLY)(int,int);
HINSTANCE hClcltr=LoadLibrary("DefExported.dll");
LPFNMLTPLY lpfnMuliply;
lpfnMuliply = (LPFNMLTPLY)GetProcAddress(hClcltr,"Multiply");
m_Rslt=lpfnMuliply(m_PartOne,m_PartTwo);
FreeLibrary( hClcltr );
|
|
|
|
|
Hi Mahmood,
I have spent enough time in getting a good idea about DLLs. Asked so many people, they used to start and get some errors and run away. My question was simple to them, "I want to write a dll to add two number".
But, your articles are funtastic, very simple, but good information.
Thanking you heartly.
Prasanna Joshi
"Life is set of uncertain events. Be carefull before making a statement"
|
|
|
|
|
class CAddDllApp : public CWinApp
{
public:
int Add(int a,int b);
CAddDllApp();
....
};
int CAddDllApp::Add(int a, int b)
{
return a + b;
}
Enter "Add @1" after the EXPORT statement, but error .
===========================================
--------------------Configuration: AddDll - Win32 Debug--------------------
Compiling...
AddDll.cpp
Linking...
.\AddDll.def : warning LNK4022: cannot find unique match for symbol "Add"
....(many warings!!!)....
LINK : fatal error LNK1152: cannot resolve one or more undecorated symbols
LINK : fatal error LNK1141: failure during build of exports file
Error executing link.exe.
AddDll.dll - 2 error(s), 14 warning(s)
===========================================
How can i do?thanx!(i'm biginner)
|
|
|
|
|
I am having the same problem!
plz~ can anyone answer this? what does that mean anyway...?
thanks.. (im new too)
|
|
|
|
|
Good job. I liked it a lot.
|
|
|
|
|
First thanks for good article
i need help, if i want to create file setup.ext or .msi by create "Setup and deployment project" in VS.NET for setup .dll, what custom action i should to code(in VC++)? (i am a beginner) in DOS i use "regsvr32"
plss
rlaley...girl
|
|
|
|
|
|
Hi rlaley,
thanx for applause ; excuse me , i'm very busy.
please describe details,what you mean setup.dll
regard
mahmood
|
|
|
|
|
I have a project(.exe) that when I compile it I can see in the compiler windows "automatically linking" the application automatic link to the DLL.
I know only two ways to link/load a dll 1. add the .lib 2. LoadLibrary function.
Do you know how to make the application to load/Link the dll automatically.
Thanks,
Yossi
Email bym040@motorola.com
|
|
|
|
|
You must add linker options yourdll.lib, In Vc++ 6 Menu-> Project-> settings ( Tab Link) , section Object/library Modules .. Add yourdll.lib. Before you must have to include header file with prototypes functions. You can use functions DLL without call Loadliibrary function.
|
|
|
|
|
Hi, Nice simple article.
I had an idea and I need some more advanced dll stuff and I was wondering if you could point me in the right direction.
I want to replace my computers winsock.dll with another winsock.dll that I create, renaming winsock.dll.
My dll would have exactly the same functions as winsock.dll, and may call functions from the renamed winsock.dll.
The reason I want to do this is so I can:
1. Get some firewall functionaility.
2. Monitor what my apps are doing. (Which ports are they listening to etc.)
I am at the reserch stage of this project. I want to scan the winsock.dll file and find what functions it exposes. (Rather than rely on dodgy & incomplete &soft socumentation.)
Any help or pointers for research, or is my idea plain stupid?
Thanks
Rob
|
|
|
|
|
hi rob
i advise you, dont do that.
thanx for your opinion about my article.
mahmood
|
|
|
|
|
Hi, thanks for the response.
Is there any particular reason for not doing it?
|
|
|
|
|
Dont physically replace system dll's with your own one's instead of that use so called API hijacking to achieve your aim.
As a matter of fact API hijacking means replacing of system API calls with your own functions wothout touching the dlls themselves.
E.g: if you install a system wide hook into the "send" function of ws2_32.dll, then every time some application calls this original system function (i.e. tries sending data), your function is called first. In your function you have the ability to monitor the parameters passed to the original function (e.g. the buffer to be sent) and call the original system function with modified parameters (e.g. a modified buffer), or not call it at all.
However, in your case when a firewall is concerned, it is not enough to hijack one single API function, like the "send" winsock function because IE does not use sockets to communicate with the outer world but it uses the wininet library, and its API functions.
For API hooking check out:
http://www.codeproject.com/system/hooksys.asp[^]
Peter Molnar
|
|
|
|
|
To answer your question, though: you can check what is in a dll by using dumpbin to get the exports table. Dumpbin is probably in the \bin path of your development package.
|
|
|
|
|
wow!
very very thanks mahmood
you resolve my old problem with this three article
|
|
|
|