| View previous topic :: View next topic |
| Author |
Message |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Fri Sep 26, 2008 3:56 am Post subject: How do i Import in MSVC++ (C) ? __declspec( dllimport ) |
|
|
Is this correct ? cause i can\\\'t get it to work:
| Code: | #define DllImport __declspec( dllimport )
DllImport void WINAPI GetPhysicallyInstalledSystemMemory(
__out PULONGLONG TotalMemoryInKilobytes
); |
and btw, Dark Byte why does my application crash when i use GetPhysicallyInstalledSystemMemory in Delphi ?
this is what i did:
| Code: | type
PULONGLONG = ^ULONGLONG;
procedure GetPhysicallyInstalledSystemMemory(kbAmount: PULONGLONG); external kernel32 name \\\'GetPhysicallyInstalledSystemMemory\\\';
ULONGLONG = UInt64;
{$EXTERNALSYM ULONGLONG}
ULARGE_INTEGER = record
case Integer of
0: (
LowPart: DWORD;
HighPart: DWORD);
1: (
QuadPart: LONGLONG);
end;
kb: PULONGLONG;
GetPhysicallyInstalledSystemMemory(@kb);
//ShowMessageFmt(\\\'Total Physicaly RAM: %d\\\', [kb]); |
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Fri Sep 26, 2008 9:00 am Post subject: |
|
|
| Code: | | #pragma comment( lib, "libname.lib" ) |
do you have the lib file?
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Fri Sep 26, 2008 11:29 am Post subject: |
|
|
[quote=\"noz3001\"] | Code: | | #pragma comment( lib, \"libname.lib\" ) |
do you have the lib file?[/quote]
ohh... thanks noz, so that\'s how you import in C/++ ?
cause in delphi it\'s different, thanks a lot nathan, noz\'s the leetness !.
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Fri Sep 26, 2008 2:31 pm Post subject: |
|
|
How are you introducing backslashes into shit you copy and paste even?
Client Requires Windows Vista SP1.
Server Requires Windows Server 2008.
Header Declared in Winbase.h; include Windows.h.
Library Use Kernel32.lib.
DLL Requires Kernel32.dll.
Just make sure you have windows.h included, and are linking against kernel32.lib. Call it as usual. And of course, you have to meet those requirements (as well as anyone that runs it)
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Fri Sep 26, 2008 4:36 pm Post subject: |
|
|
| slovach wrote: | How are you introducing backslashes into shit you copy and paste even?
Client Requires Windows Vista SP1.
Server Requires Windows Server 2008.
Header Declared in Winbase.h; include Windows.h.
Library Use Kernel32.lib.
DLL Requires Kernel32.dll.
Just make sure you have windows.h included, and are linking against kernel32.lib. Call it as usual. And of course, you have to meet those requirements (as well as anyone that runs it) |
i was using proxies, sorry that causes the /// issue.
and i know it's for Vista SP1 only, just wanna see if it works lol.
and can i see a code snippet on how to import ? cause i know how to export only =/ (bummer)..
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Fri Sep 26, 2008 5:41 pm Post subject: |
|
|
You're over-complicating this.
include windows.h...
#include <windows.h>
then just link against kernel32, set it in the linker options or just do it like (you're probably already linking against it by default to begin with):
#pragma comment(lib, "kernel32.lib")
Then just call it.
|
|
| Back to top |
|
 |
pkedpker Master Cheater
Reputation: 1
Joined: 11 Oct 2006 Posts: 412
|
Posted: Fri Sep 26, 2008 6:16 pm Post subject: |
|
|
import is for loading custom dlls in your project (apart from Loadlibrary)
export is for exporting (making custom dlls).
_________________
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sat Sep 27, 2008 4:37 am Post subject: |
|
|
| slovach wrote: | You're over-complicating this.
include windows.h...
#include <windows.h>
then just link against kernel32, set it in the linker options or just do it like (you're probably already linking against it by default to begin with):
#pragma comment(lib, "kernel32.lib")
Then just call it. |
it won't work, weird!
| Code: | #include <windows.h>
#include <stdio.h>
#pragma comment(lib, "kernel32.lib")
void main(void)
{
ULONGLONG kbRAM;
GetPhysicallyInstalledSystemMemory(&kbRAM);
printf("Total Physical Ram: %li\n", kbRAM);
} |
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sat Sep 27, 2008 11:22 am Post subject: |
|
|
use int main
Look at it under the debugger, what is it returning?
|
|
| Back to top |
|
 |
|