Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » DLL and U++ type
DLL and U++ type [message #2182] Mon, 03 April 2006 14:45 Go to next message
mauro.bottizzo is currently offline  mauro.bottizzo
Messages: 2
Registered: April 2006
Junior Member
hi,

I am writing an DLL, using:

extern "C" { ... }

When i defining the "C" functions it's possible use U++ type, like "String", "Value", etc ...?? If no, only the poiners, like: String&, Value&, etc??

Thanks.
Re: DLL and U++ type [message #2192 is a reply to message #2182] Mon, 03 April 2006 18:58 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14105
Registered: November 2005
Ultimate Member
mauro.bottizzo wrote on Mon, 03 April 2006 08:45

hi,

I am writing an DLL, using:

extern "C" { ... }

When i defining the "C" functions it's possible use U++ type, like "String", "Value", etc ...?? If no, only the poiners, like: String&, Value&, etc??

Thanks.




I am not 100% sure, but I think yes, it is possible.... (extern "C" in practice just removes name mangling from your functions, means overloading will be impossible, but nothing more).

Mirek
Re: DLL and U++ type [message #2199 is a reply to message #2192] Mon, 03 April 2006 22:58 Go to previous messageGo to next message
mauro.bottizzo is currently offline  mauro.bottizzo
Messages: 2
Registered: April 2006
Junior Member
Well,
it's running.

Last little question about that.

I need to keep the pointer of an object, returned from my DLL function, and use it in others DLL function.

First solution that i know is to include with the DLL the header with my class declaration; but I don't like that.
Second solution that i found is to return the pointer like a integer value, named "handle", and use it like a pointer when need again. I am thinking something like when using "new", but the pointer it's get from my integer var. Example:

bool MyDllFunction(unsigned int handle, ...) {
MyType *foo;
foo = (MyType *)handle;

MyType->....
...


}

All this now it's running well, but the question is: It's correct to use an integer for store an pointer? Or need to use an different var type??

thanks.
Re: DLL and U++ type [message #2202 is a reply to message #2199] Mon, 03 April 2006 23:43 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14105
Registered: November 2005
Ultimate Member
Well, it is not 100% correct, but more or less OK. Using 'int' obviously will fail on 64-bit platform.

If you want to be more correct, use intptr_t, which is integral type guaranteed to be able to hold the pointer.

Mirek
Re: DLL and U++ type [message #2322 is a reply to message #2182] Sat, 08 April 2006 12:41 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
Another way to pass around unknown pointers is to use (void *) type. I like this because I understand it even without knowing too much about C/C++ Smile. (intptr_t is sort of higher magic for me Smile )
Re: DLL and U++ type [message #2330 is a reply to message #2322] Sat, 08 April 2006 12:55 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14105
Registered: November 2005
Ultimate Member
mr_ped wrote on Sat, 08 April 2006 06:41

Another way to pass around unknown pointers is to use (void *) type. I like this because I understand it even without knowing too much about C/C++ Smile. (intptr_t is sort of higher magic for me Smile )


There is nothing magic about intptr_t, just one of standard headers (I think stdlib.h, but not quite sure) has something like

#ifdef *****
typedef int intptr_t;
#endif

#ifdef *****
typedef _int64 intptr_t;
#endif

(where ***** depends on platform, compiler etc...)

Mirek
Re: DLL and U++ type [message #2428 is a reply to message #2182] Wed, 12 April 2006 14:01 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
stdlib.h *is* higher magic for me. Smile

I never really learned C or C++, I dislike to learn too many implementation-dependent details. When I work with some new programming language, I simply read language reference guide to learn syntax and basic commands, take some framework which inits the application, and start from there...

That allowed me to stay "virgin" clean from Win32 API, STL and many more commonly used libraries. Only one which I really did study thoroughly was DirectX, otherwise I tend to pick up as small subset as is needed to finish my work, or just do the main algorithm and let someone else to finish those API things.

Than again, I find clean assembly source more readable than some high-level templatized C++ source, so I'm sort of programmer dinosaur. Smile

(void *) is "language reference" thing and works for me.
stdlib.h is some foreign source I never bothered to study and learn. Razz


WARNING: I'm not suggesting anyone should follow my path, you can end up coding things which are ready to use in some nice library. You should have at least idea what those foreign libraries are capable of - to make sure you don't reinvent the wheel all the time.
But maybe a lesson can be learned here, it's not always that important to know every API from head... OTOH language reference is IMHO always important. Platforms and libraries do change often, language stays the same (ok, evolves a bit too, but surely not as fast as libraries). If somebody is learning Win32 API and doesn't understand C++ (language part) very good, he has very likely wrong priorities, and will suffer a lot later during development.
Re: DLL and U++ type [message #2469 is a reply to message #2428] Thu, 13 April 2006 18:22 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14105
Registered: November 2005
Ultimate Member
mr_ped wrote on Wed, 12 April 2006 08:01


(void *) is "language reference" thing and works for me.



There is a subtle but important difference between (void *) and uintptr_t - uintptr_t is _integral_ type (like int or long). E.g. you can perform full integral arithmetics with it (example: think about printing the address contained in pointer Wink

The problem uintptr_t solves is that there is no fixed fundamental type that can be safely used to store and retrieve pointers. It is e.g. "int" or "unsigned int" on most 32-bit platforms, but that is not true on 64-bit CPUs anymore.

Thus uintptr_t solves this issue.

Mirek
Re: DLL and U++ type [message #2482 is a reply to message #2182] Fri, 14 April 2006 03:36 Go to previous message
gprentice is currently offline  gprentice
Messages: 260
Registered: November 2005
Location: New Zealand
Experienced Member

Just for the record - intptr_t and uintptr_t aren't part of standard C++ or C90 and in C99 they're optional and in stdint.h header - but they appear to be "standard" extensions available in many C++ compilers and in all U++ supported compilers Wink

Graeme
Previous Topic: capturing stdout/err/in of subprocess
Next Topic: Inverse palette conversion algorithm...
Goto Forum:
  


Current Time: Fri Nov 01 01:31:17 CET 2024

Total time taken to generate the page: 0.01755 seconds