library help

Posts 1–8 of 8 · Page 1 of 1
library help
im trying to create a custom class library (dll) file that i can add as a reference to any project
for example if in the library if i set it up like so

Code:
typedef void (*AtomCmd_t)(int clientNum, int type, const char *text);
AtomCmd_t mycmd = (AtomCmd_t)0x48573842;
i could call this function in my c++ project using this line
Code:
mycmd(1,mytype,"Text here");
can someone explain a good way to accomplish this? I Know how to pass the class or a certain function itself but what about the defines?
You can use LoadLibrary and GetProcAddress to call your functions externally.

Code:
//DLL named david.dll:

extern "C" int DavidIsCool(int x)
{
	return x;
}
Code:
//other program:

typedef int(__cdecl* fDavidIsCool)(int);
fDavidIsCool DavidIsCool = NULL;

HMODULE dll = LoadLibrary("david.dll");

DavidIsCool = (fDavidIsCool)GetProcAddress(dll,"DavidIsCool");

DavidIsCool(1337);
Quote Originally Posted by Void View Post
You can use LoadLibrary and GetProcAddress to call your functions externally.

Code:
//DLL named david.dll:

extern "C" int DavidIsCool(int x)
{
	return x;
}
Code:
//other program:

typedef int(__cdecl* fDavidIsCool)(int);
fDavidIsCool DavidIsCool = NULL;

HMODULE dll = LoadLibrary("david.dll");

DavidIsCool = (fDavidIsCool)GetProcAddress(dll,"DavidIsCool");

DavidIsCool(1337);
one question about this

Code:
typedef int(__cdecl* fDavidIsCool)(int);
fDavidIsCool DavidIsCool = NULL;
can i put that into the library(david.dll) to or does that have to be in the program itself. Because that is more of what im trying to do.
Quote Originally Posted by XiAtomikiX View Post
one question about this

Code:
typedef int(__cdecl* fDavidIsCool)(int);
fDavidIsCool DavidIsCool = NULL;
can i put that into the library(david.dll) to or does that have to be in the program itself. Because that is more of what im trying to do.
That part has to be part of the program you're calling the function from.
@OP "I Know how to pass the class or a certain function itself but what about the defines?"

You mean you want to have access to the defines from your 2nd C++ project, the app.
Like.. david.dll->someProperty; like global variable / constant ?


"To define preprocessor macros we can use #define. Its format is:

#define identifier replacement
"

it's a preprocessor thing, so it actually replaces ur code w/ literally that value. I'm not sure if it preserves that define/value in the final .dll ? Or is that not what you meant?
--maybe make them public constants, instead of #define's ?

edit: nvm, not sure w/ function prototypes statements retracted.
Quote Originally Posted by Void View Post
Snipped
Quote Originally Posted by abuckau907 View Post
Snipped
basically what i want to do is this
in my dll file(The library) I want to store data similar to below
Code:
typedef void (*AtomCmd_t)(int clientNum, int type, const char *text);
AtomCmd_t mycmd = (AtomCmd_t)0x48573842;
Then my other Project(Program) use the dll library as a reference and call the functions below like so.
Code:
mycmd(1,mytype,"Text here");
what's the 0x48573842 ?

um.. just make a public void function that calls mycmd internally? This has nothing to do w/ dll injecting right?
Quote Originally Posted by abuckau907 View Post
what's the 0x48573842 ?

um.. just make a public void function that calls mycmd internally? This has nothing to do w/ dll injecting right?
no this is not dll injecting. Im building a public library for people to use as a plugin towards my directX project I am building but the problem is i donot what the functions public meaning i will not give access to the source i want it hidden thats why im building a library hopefully.
I am building a Media Center app using DirectX which its pretty close to being finished. This is a script to allow customization of the
MediaCenter. So people can plugins.
Posts 1–8 of 8 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us