Hi - I've been at this for hours, so... say hello to my first post.
I'd like to allow my many cpp files to call on a function from DLL funcs I've brought in using LoadLibrary/GetProcAddress/etc, but, when I include the header file into the multiple cpp's, I get the "Already defined" compiler error. I'm kindof a noob, so I've been throwing #pragma once at the start of each and every file, and using the extern keyword prodigiously, but, I'm not sure how to handle this situation.
Here are samples of my code - hopefully it's enough to get your help.
func.h
// Declaring the handles for the dll, and function pointers. I initialize this
// in main.c (in the hopes that I only define it once... to no avail)
#pragma once
#ifndef LIB_SET
#define LIB_SET 1
HINSTANCE dll_name;
typedef int (CALLBACK* func1_pt)(int);
func1_pt func1;
#endif
cpp1.cpp
// Got a bunch of stuff going on in files like this one that include func.h in order
// to make use of its functions. Even when I have just one of these files, I get
// a compiler error.
#pragma once
#ifndef LIB_SET
#include "func.h"
#endif
void cpp1() {
func1();
}
main.cpp
#pragma once
#ifndef LIB_SET
#include "func.h"
#endif
#include "cpp1.h"
/*dll_name = LoadLibrary("dll_name.dll");
func1 = (func1_pt)GetProcAddress(dll_name,"FUNC1");*/
cpp1();
When I try to compile the error msg reads similarly to: "cpp1.obj : error LNK2005: "void (__stdcall* func1)()" (?func1@@3P6XHH@ZA) already defined in main.obj"
Based on my Googling/Binging, I'm thinking that my typedef line counts as an allocation, which cannot be done twice, but then, I'm not sure how else I can call the dll functions, which themselves are workarounds for workarounds, but that's another story...
Any help would be much appreciated. Hopefully I've provided enough info.
Thanks,
SM