473,563 Members | 2,695 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

#define ABC_DLL_F_GET(h Dll, func_name) \
{ \
(fproc_t &)lpfn##func_na me = abc_GetProcAddr ess(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 1487
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********@gmai l.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.co mwrote:
Hua.wat...@gmai l.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********@gmai l.com kirjutas:
#define ABC_DLL_F_GET(h Dll, func_name)
\ {
\
(fproc_t &)lpfn##func_na me = abc_GetProcAddr ess(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::s tring, fproc_tfunc;

void ImportAbcFunc(H DllType hDll, const char* func_name) {
func[func_name] = abc_GetProcAddr ess(hDll, func_name);
}
ImportAbcFunc(h Dll, "foo");
ImportAbcFunc(h Dll, "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
7175
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 set of pages that get the w3c tick for XHTML 1.0 Strict, and CSS2. So far, I have succeeded, thanks to the great information in these groups. Now,...
14
1640
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
3600
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
13213
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
1413
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. We know the "register" keyword suggests the compiler keep the following variable in a register. We also have the "inline" suggestion in C++ to...
10
1632
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. It's little more than something needed for the preprocessor, apart from that it is ancient junk. It's not needed in Java or other modern OOP...
3
1941
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 = VOL + VAL\ + VOL - VOL\ + VOL - VOL There are 2 more similar but bigger #define used by my program. They
13
2647
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
2559
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: const char *s = string_mapper<thetype>(); However I do not know the string to be associated with the type at compile time, and will need a way to set...
0
7583
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7638
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7948
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6250
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.