|
Hello,
I need to call all global functions(probably several) that are exported in a DLL but using only single generic pointer.
I am loading dll with LoadLibrary function and getting all exports with GetProcAddress, this needs to be type casted with that function pointer of which type the function is really itself.
I don't know how many exported functions are there in DLL and how many no of parameters on which they are operating.This prevents me to define generic type of pointer for every function call working for GetProcAddress.(void* is possible but still we cannot generate function call, gives compile time error)
This problem can be resolved when you have all member functions of some class. You can rely on 'this' of that class and function pointer can be declared of that class. Moreover all functions with single function pointer can be called with some boost API bindings.
But for all global and EXPORTED functions of DLL, how this problem can be solved.
Regards
Muhammad Usman Khalil
|
|
|
|
|
You can't call a function without knowing the number and type of parameters it requires - whether a free function or a member function, whether statically linked or dynamically linked, whether directly or through a pointer. How would you know what arguments to provide? How would the compiler be able to implement the call, passing arguments correctly and using the correct calling convention?
To be called via a pointer, member functions of a class need everything that a free function would plus an object to act on.
If you really needed to use void pointers, you will need to find or put together something that couples the pointers with some sort of identification of the function signature so that the pointer can be appropriately cast when used. You would also need to work something out to provide the proper arguments and dealing with any return value.
Either via documentation, header file, or some mechanism in the dll itself, you need to have information about the exported functions in order to use them.
Good Luck.Please do not read this signature.
|
|
|
|
|
You can use the dumpbin command with /EXPORTS to get the parms.
/edit sorry, only seems to show the parms for class functions.modified on Tuesday, February 9, 2010 4:28 PM
|
|
|
|
|
Use a def file. I've never had to use GetProcAddress and regularly export void * functions with dll's.
|
|
|
|
|
Respectfully !!
My goal to call every exported function of DLL without need to declare function pointers.If DLL contains 100 funcs(exported methods) having different types(i.e their return type and in/out params) I need 100 function pointers. Every time GetProcAddress needs to be type casted with those 100 func pointers. Creates horrible maintainaince nightmare. Every time new function included, you need pointer of that type to be declare in code.
Wot about delegates..?
Delegate usage prevents user to use GetProcAddress and require any function pointer to work with.
It wraps all functions to which you want to call at run time. Thus we'll not need any function pointer or need to know the type for that pointer.
Once we know the function Name,in/out params and their types, Without using GetProcAdress, we can call these functions using delegates.
But for this we need to work in managed code sustains within C#.NET
Wot about delegates..?
Delegate usage prevents user to use GetProcAddress and require any function pointer to work with.
It wraps all functions to which you want to call at run time. Thus we'll not need any function pointer or need to know the type for that pointer.
Once we know the function Name,in/out params and their types, Without using GetProcAdress, we can call these functions using delegates.
But for this we need to work in managed code sustains within C#.NET
Regards
Usmanmodified on Wednesday, February 10, 2010 3:37 AM
|
|
|
|
|
glitteringsound wrote: My goal to call every exported function of DLL without need to declare function pointers.If DLL contains 100 funcs(exported methods) having different types(i.e their return type and in/out params) I need 100 function pointers. Every time GetProcAddress needs to be type casted with those 100 func pointers. Creates horrible maintainaince nightmare. Every time new function included, you need pointer of that type to be declare in code.
Maybe i dont understand you problem well but i would think of putting in a function in the DLL that returns a pointer to an array that contains for all functions in the DLL a function-pointer. Then only this function needs to be called to get the rest (this idea is also in CORBA)....
|
|
|
|
|
How to import a file into PE header of an exe then load that file from within modified exe
i searched CP about this but found nothing relevant
the articles i found were mostly code injection based
simply i want to import a file ( ex: BMP) into PE header of a compiled exe
then read this file through a predefined function from within compiled exe
is it possible , if possible could you show me how to do
thanks
|
|
|
|
|
only_jack wrote: simply i want to import a file ( ex: BMP) into PE header of a compiled exe
If you mean do this at run time then, no it is not possible. Perhaps you are thinking of embedding a file in your program's resources, in which case see here[^].MVP 2010 - are they mad?
|
|
|
|
|
no , i will compile exe and then create another program to import specified file to compiled exe , target exe will not work at this time
i want to implement a simple compiler for my own use
i have a program that parses a custom file format
currently i am importing files to resource section already
through another program that i made
so select file and import into resource section of target exe
then i run modified exe it will load that file from resource and execute
resource method works very well but i do not find it secured enough
i want to implement some thing with PE headers
now i want to import file into PE header of a precompiled exe and then read at runtime , through functions i wrote before compile target exe
|
|
|
|
|
only_jack wrote: resource method works very well but i do not find it secured enough
The BMP file you want to insert is that sensitive?
Once you replace the PE headers with some other file, that modified file will no longer function. So what purpose does it serve?
The cynic in me smells a Trojan horse (i.e., trying to hide the nefarious file from AV software by wrapping it with some other legitimate file)."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
DavidCrow wrote: The cynic in me smells a Trojan horse (i.e., trying to hide the nefarious file from AV software by wrapping it with some other legitimate file).
Bingo.L u n a t i c F r i n g e
|
|
|
|
|
why are you getting all wrong
DavidCrow wrote: The BMP file you want to insert is that sensitive?
BMP was an example i will use something else , maybe you forget to do your glasses while reading my question
DavidCrow wrote: Once you replace the PE headers with some other file, that modified file will no longer function. So what purpose does it serve?
i never said that i want to replace
i want to replace nothing , i want to import a new section
DavidCrow wrote: The cynic in me smells a Trojan horse (i.e., trying to hide the nefarious file from AV software by wrapping it with some other legitimate file).
why i will do this for a malicious purpose , all of AVs can scan PE headers you should know this as a MVP ,
if i want to hide a file from user or AVs , i can easily import it to a
NTFS portion as a ADS but i am killing my hours against them
if i was looking for some malicious resources trust me i can find them on the net in few seconds , even in codeproject site
there are lots of articles like how to inject your code to another process maybe first you should check those articles firs which you approved and publised
finally , i will explain it a bit more
the compiled exe uses a %80 modified Lua interpreter do you know Lua
and i am importing some modified Lua scripts in to compiled exe's resources
and then i am getting these scripts through resource API functions
then redirect the file buffer to luaL_loadbuffer() function of LUA C API
interpreter parses this file and generates some reports
so i am uploading this file to FTP and users download it priodically and run to get some report about a main program ,and it will edit some portions of main installition if necessary with user's permission (i hope now you do not get this like i am making a pacher)
finally it will generate a report like below and present some options to user
-------------------------------------------------
your installition needs an update
x database is absolete , y file needs a update ,
the purpose that you having trouble to understand was the automation of some report procedures
do you know an idiot who spends hours to do above to make a simple damn trojan , whereas it can be done within minutes
|
|
|
|
|
only_jack wrote: the purpose that you having trouble to understand was the automation of some report procedures
We are having trouble understanding it because you are not explaining it! Your original post mentioned nothing about automated reports, it merely said you wanted to modify an exe file by importing a bitmap resource - hence the suspicion that you were trying something illegal. Your description above still confuses me, if a program needs runtime parameters that are not compiled into its resources then why not just read some sort of parameter or config file, as does just about every commercial application in the world?MVP 2010 - are they mad?
|
|
|
|
|
Despite your comments I can see a) no way to do this and b) no purpose for it. But if you ever solve the problem do please write an article about it. MVP 2010 - are they mad?
|
|
|
|
|
Hi
I did following:
struct BaseFactory
{
typedef std::map<std::string, CBaseClass*(*)()> map_type;
...
protected:
static map_type * getMap()
{
if(!map) { map = new map_type; }
return map;
}
private:
static map_type * map;
};
template<typename T>
struct RegisterUserClass : BaseFactory
{
RegisterUserClass( std::string const& s )
{
getMap()->insert(std::make_pair(s, &createT<T>));
};
};
myCode.h
class CMyCode
{
...
private:
RegisterUserClass<CMyCode> reg;
}
myCode.cpp
RegisterUserClass<CMyCode> reg("CMyCode");
I got a link error. I know the "map" did not get initialized. How can "map" be initialized for my case?
Thanks,
|
|
|
|
|
The linker is complaining that the static member:
private:
static map_type * map;
doesn't have a definition. Try adding this to your basefactory.cpp file:
BaseFactory::map_type* BaseFactory::map = NULL;
|
|
|
|
|
Hi all,
I do hope somebody has some experience in this field... We are trying to port a project that we have taken over from another party from Visual Studio 6 to Studio 2008 (since we need to migrate to a 64bit platform). Part of the project uses type libraries. In itself this works fine (except for al the warnings that we need to tackle of course) The problem is that we have a dll A that is #imported into project B. This generates another dll (and type library) We then make a project C in which we #import both dll A and dll B. However, when importing dll B, the linker complains about not being able to find types from dll A (it replaces them with _unknown_ or something)
This all worked fine in studio 6. Has anyone got any idea as to how to tackle this issue. I do assume there is something trivial that needs to be defined, the question is ---what---??
Thanks in advance.
William
|
|
|
|
|
|
CString.Format can help in this! "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Could you explain how i can insert it into my sql query to show how it works?
|
|
|
|
|
try
char* NewTitle = "Monaco";
char* NumofShows = "2"; Failure is Success If we learn from it!!
|
|
|
|
|
Sorry, i do not get u? i mean, how do we insert the variables "NewTitle" and "NumofShows" into the sql statement so it can read the varaibles..
|
|
|
|
|
mysql_query(connection, "INSERT INTO main (NumofShows , Title) VALUES('12', 'Home')")
<br />
char* NewTitle = "Monaco";<br />
char* NumofShows = "2";<br />
<br />
CString InsertQuery= "INSERT INTO main (" + (CString)NumofShows +","+(CString) NewTitle +") VALUES('12', 'Home')";<br />
<br />
mysql_query(connection,InsertQuery);
before that change your project properties unicode into multibyte ..i hope this ll work ..if any error comes send it !!! Failure is Success If we learn from it!!
|
|
|
|
|
mysql_query(connection, "INSERT INTO main (NumofShows , Title) VALUES('12', 'Home')")
Sorry i think you misunderstood what i meant. Normally, for the values, it has to be hardcoded in, for example, having to put 12 and home inside.
What i meant is, for example, if the values to be inserted are in a variable , like ..
string NewShowName = "Danger"
int NewNumberofShow = "2"
How do i put in this variables (NewShowName, NewNumberofShow) into the sql statements at VALUES so the program can read the values inside this variables and then save them in the database
|
|
|
|
|
Might I suggest you will probably get a better response in the Database forum for this question. MVP 2010 - are they mad?
|
|
|
|