Why does this not work and make an error?

Windows specific forum
mikecaliber
User
User
Posts: 22
Joined: Sun Feb 15, 2004 5:34 pm

Why does this not work and make an error?

Post by mikecaliber »

ws_psapi_lib = 1
ws_psapi_h.l = OpenLibrary(ws_psapi_lib,"PSAPI.DLL")
*ws_EnumProcessModules = IsFunction(ws_psapi_h,"EnumProcessModules")
CloseLibrary(ws_psapi_lib)



Enter that code into your pb and run it.... I get a Windows runtime error. I am trying to use that .dll call (EnumProcessModules) as it is not one of the "built-in" calls in PB. I don't think that the PSAPI library is supported natively by PB yet, right?

best,
cal
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

Are you sure that the dll is opened properly (you don't check this in the code you posted here)?
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

You must pass the 'ws_psapi_lib' value to IsFunction, not the other one.
quidquid Latine dictum sit altum videtur
mikecaliber
User
User
Posts: 22
Joined: Sun Feb 15, 2004 5:34 pm

Post by mikecaliber »

thanks freak!

i am an idiot for missing that-

in the following code,

DWORD FindModule (HANDLE hProcess, const char* sModule)
{
HMODULE hMod[1024];
DWORD cbNeeded;

If( EnumProcessModules( hProcess, hMod, SizeOf(hMod), &cbNeeded) )
{
For ( unsigned int i=0 ; i < (cbNeeded / sizeof(HMODULE)) ; i++ )
{
char sModName[MAX_PATH];

GetModuleBaseNameA( hProcess, hMod, sModName, SizeOf(sModName) );

If ( !stricmp(sModName, sModule) )
{
Return (DWORD)hMod;
}
}
}

Return 0;
}

which is c++, what would I do to make the conversion to PB. for instance-

the HANDLE type, what do i use there? the HMODULE type? what to use there? swap DWORD with .l?

also, what would be a good way to convert the line:

HMODULE hMod[1024];

into pb? what does this do and what would be the code that would represent this in pb?




best,
mike
mikecaliber
User
User
Posts: 22
Joined: Sun Feb 15, 2004 5:34 pm

Post by mikecaliber »

bump for more views
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Good programmers don't comment their code. It was hard to write, should be hard to read.
Post Reply