473,394 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to realize ## without #define (maybe with inline)?

#define ABC_DLL_F_GET(hDll, func_name) \
{ \
(fproc_t &)lpfn##func_name = abc_GetProcAddress(hDll, #func_name); \
}

If I want to modity this #define macro to something in good C++ style
like a inline func, how should I do$B!)(B

Thanks
Sep 15 '08 #1
4 1480
by the way, this macro is used in an .cpp to provide explicit linking
of DLL. It provides accessing to exported functions of DLL just like a
normal function, as well as use the same header file provided by the
DLL

Is there any good library provides this functionality ? Then I need
not write it myself

Sep 15 '08 #2
Hu********@gmail.com wrote:
by the way, this macro is used in an .cpp to provide explicit linking
of DLL. It provides accessing to exported functions of DLL just like a
normal function, as well as use the same header file provided by the
DLL

Is there any good library provides this functionality ? Then I need
not write it myself
Maybe you should ask on a windows programming group where dlls are topical.

--
Ian Collins.
Sep 15 '08 #3
On Sep 14, 10:45*pm, Ian Collins <ian-n...@hotmail.comwrote:
Hua.wat...@gmail.com wrote:
by the way, this macro is used in an .cpp to provide explicit linking
of DLL. It provides accessing to exported functions of DLL just like a
normal function, as well as use the same header file provided by the
DLL
Is there any good library provides this functionality ? Then I need
not write it myself

Maybe you should ask on a windows programming group where dlls are topical.
I'm not so sure. I'm as much of an off-topic cop as the next guy, and
it seems that what he's really looking for is how to replace the
(ugly) macro with an inline function, which *is* on topic.

Sep 15 '08 #4
Hu********@gmail.com kirjutas:
#define ABC_DLL_F_GET(hDll, func_name)
\ {
\
(fproc_t &)lpfn##func_name = abc_GetProcAddress(hDll,
#func_name); \
}

If I want to modity this #define macro to something in good C++ style
like a inline func, how should I do
If your goal is not to repeat the function name, then the best I can
imagine is something like (warning - untested code!):

std::map<std::string, fproc_tfunc;

void ImportAbcFunc(HDllType hDll, const char* func_name) {
func[func_name] = abc_GetProcAddress(hDll, func_name);
}
ImportAbcFunc(hDll, "foo");
ImportAbcFunc(hDll, "bar");

int result = (*func["foo"])(arg1, arg2);

This works better if all functions have the same signature.

Anyway, I see nothing awfully wrong with the macro as well here.
Preprocessor is part of C++ after all.

hth
Paavo
Sep 15 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

54
by: Max Quordlepleen | last post by:
Apologies for the crossposting, I wasn't sure which of these groups to ask this in. I have been lurking in these groups for a week or so, trying to glean what I need to design a simple, clean...
14
by: Blue Ocean | last post by:
My c++ text tells me that I should define methods this way: class Stack { int method(double t); Stack(int s); ... } int Stack::method(double t)
5
by: eiji | last post by:
Hi folks, I hope this is not "off topic"! :-) Consider the next code: /* Declarations of types that could become platform-dependent */ #define MyChar char #define MyInt int
4
by: thinktwice | last post by:
i have just made a test project :(win32 console) //file : func.h #ifndef _FUNC_H_ #define _FUNC_H_ void func1() { return; };
7
by: Ancient_Hacker | last post by:
In days of old, for no discernible reason, many CPU's had the ability to execute one or more instructions out of registers. Not very common today. Which brings up a semi interesting point. ...
10
by: collection60 | last post by:
Will C++ ever have Java-like multiple level compiling? So that we can dump the old model of having to first declare then write the code? I find the declaration wastes so much time in coding....
3
by: Shirsoft | last post by:
I have used a #define to reduce code size but it greatly increases the compile time (from a few secs to 5 mins) The #define is quite simple #define UPDATE_VOL_SLICE(VOL,I,J,K, VAL)\ VOL = ...
13
by: Szabolcs Szucs | last post by:
Hi all, How can I exchange the values of two integer variable without using an auxiliary one. =--= kotee
5
by: alan | last post by:
Hello world, I'm wondering if it's possible to implement some sort of class/object that can perform mapping from class types to strings? I will know the class type at compile time, like so:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.