Please login or register.

Login with username, password and session length
Advanced search  

News:

For WME related articles and tutorials visit WME Resource Center.

Author Topic: DLL loading  (Read 7263 times)

0 Members and 1 Guest are viewing this topic.

Pipec

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 57
    • View Profile
    • stereopyram
DLL loading
« on: July 25, 2009, 05:41:26 PM »

Sorry for bad English. This is a computer translation from Russian language.
I want to load the DLL library. I use script:

Code: [Select]
external "kernel32.dll" int LoadLibraryA(string);
external "kernel32.dll" FreeLibrary(int);
external "kernel32.dll" int GetLastError();

var hDll = LoadLibraryA("magic.dll");
Game.Msg(GetLastError());
FreeLibrary(hDll);
Game.Msg(GetLastError());

But "LoadLibrary" return error 2 - ERROR_FILE_NOT_FOUND, or 126 - ERROR_MOD_NOT_FOUND.
I placed the dll in the folders: system32, WME folder, project folder, data folder. I used the absolute and relative path. But in all cases I get an error.

library, of course, working, I took her here astralax.ru.
Working example of the developer (executable only, dll present) http://letitbit.net/download/0990.02a8ad5bcd8c88c3a093bfa61/demo.zip.html
Example with source code in C++ (without visualization, dll present) http://www.astralax.ru/hlam/LoadLibraryTest.rar

Why can not load library? When I change magic.dll, for example, kernel32.dll, LoadLibrary returns 0 - ERROR_SUCCESS
   
Thank you for your help!
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: DLL loading
« Reply #1 on: July 25, 2009, 06:03:53 PM »

I'm afraid you can't rely on GetLastError in scripts, because it's pretty likely WME calls some API functions internally between the script lines. Instead use Game.Msg() to display the hDll variable. If it contains zero, LoadLibrary failed. If not, the library is loaded.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Pipec

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 57
    • View Profile
    • stereopyram
Re: DLL loading
« Reply #2 on: July 27, 2009, 10:05:12 AM »

Thank you! This really works!  ::rock
Logged

Pipec

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 57
    • View Profile
    • stereopyram
Re: DLL loading
« Reply #3 on: July 27, 2009, 11:01:29 AM »

Then another question. DLL have function:
Code: [Select]
int Magic_OpenFile(
   const char* file_name,
   HM_FILE* hmFile
);

Сalling convention - cdecl

In the engine, I declare it so:
Code: [Select]
external "magic.dll" cdecl int Magic_OpenFile(string, int);

That is right?
Because when I is calling:
Code: [Select]
var PtcFile;
Magic_OpenFile("test.ptc", PtcFile);
WME crushing with application error.

Quote
-----------------------------------------------------------------
---------- wme 1.8.010 crash report: 27-07-2009, 12:55 ----------
-----------------------------------------------------------------
wme.exe caused a EXCEPTION_ACCESS_VIOLATION in module magic.dll at 001B:6A581334
EAX=00000000  EBX=00000001  ECX=6A5D1060  EDX=0000000A  ESI=003E4880
EDI=0012FDA4  EBP=0012FD74  ESP=0012FD0C  EIP=6A581334  FLG=00010213
CS=001B   DS=0023  SS=0023  ES=0023   FS=003B  GS=0000
Stack trace:
001B:6A581334 (0x6A5D1060 0x024E0FF0 0x00000000 0x00BE7AE0) magic.dll
001B:6A58B9F1 (0x024E0FF0 0x00000000 0xB677B752 0x00000010) magic.dll, Magic_OpenFile()+33 byte(s)
001B:00455D48 (0x00BE7D90 0x00BE7CE0 0x00BE7AE0 0x00000010) wme.exe
001B:00456A82 (0x00AB43B8 0xFFFFFFFF 0x00BE6F40 0x00000000) wme.exe
001B:00AB0101 (0x00454790 0x00455920 0x69726353 0x63207470) <UNKNOWN>
001B:00455FD0 (0x8B550C41 0x5614246C 0x5718718D 0x18247C8B) wme.exe
001B:8D53128B (0x00000000 0x00000000 0x00000000 0x00000000) <UNKNOWN>
Logged

Pipec

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 57
    • View Profile
    • stereopyram
Re: DLL loading
« Reply #4 on: July 27, 2009, 02:51:08 PM »

Realized their mistake!   ::)

"HM_FILE* hmFile" this is not a variable, this pointer. Solved the problem using MemBuffer
Logged

Pipec

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 57
    • View Profile
    • stereopyram
Re: DLL loading
« Reply #5 on: July 28, 2009, 09:55:57 AM »

And yet the question  ;)

The external function is called in a loop and returns a pointer at structure (membuffer object) or null. Null - a sign of the end of the loop. I use script:
Code: [Select]
external "magic.dll" cdecl membuffer Magic_GetNextParticle();

var doPart = true;
var struc = new MemBuffer(20);

while(doPart)
{
  struc = Magic_GetNextParticle();
  if (struc == null)
  {
    doPart = false;
  }
  else
  {
    ... operations on the data from the structure ...
  }
}

But the condition if (struc == null) is not fulfilled, when external function return null.
I used the condition if (struc.GetInt == null), but received an error, when external function return null
Quote
11:43:   Cannot use Set/Get methods on an uninitialized memory buffer

Question: How in my case, to determine that the external function returns a null?
« Last Edit: July 28, 2009, 09:57:34 AM by Pipec »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: DLL loading
« Reply #6 on: August 01, 2009, 09:56:03 PM »

You could test null by comparing it with zero. But it won't work anyway. The DLL function apparently returns a pointer to some structure. It's not possible to access such structure from scripts.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Pipec

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 57
    • View Profile
    • stereopyram
Re: DLL loading
« Reply #7 on: August 02, 2009, 07:31:09 PM »

There is no way to identify the null pointer  ???
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: DLL loading
« Reply #8 on: August 02, 2009, 09:31:40 PM »

Yes there is, null pointer is zero.

if (struc == 0) ...

What I'm saying is that you will not be able to use a structure returned as a pointer from the scripts.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave
 

Page created in 0.019 seconds with 24 queries.