PDA

View Full Version : Where Am I?



BloodQuest
08-25-2006, 06:05 PM
Hi all,

I'm sure I'm being stupid, but can't think how a plugin can work out where it was run from.

Anyone know the answer?

Simon

MiniFireDragon
08-25-2006, 10:54 PM
If I understand you correctly, this might be what you are looking for. A plugin is nothing more then a DLL that has an extension of .p. You need to add the plugin to the Layout or Modeler plugin window. When Lightwave starts it loads the plugin (aka DLL).

ShawnStovall
08-25-2006, 11:04 PM
Also, the plug-in doesn't have to be in any specific folder.

BloodQuest
08-26-2006, 12:02 AM
What I'm asking is when the plugin runs, how can it detect where it's been installed?

A bunch of my stuff uses a .cfg file in the LW config dir. To find that, I can use

cfgdir = dirinfo( LWFTYPE_SETTING );

I'm wondering how a plugin can store a .ini in its own folder. Obviously, I could have it read lwext*.cfg and "find itself" but there must be a C function that returns a file handle or something to the plugin itself.

Obviously, this is precisely because it could be in any folder...

Simon

Check out Smart-Save and Zip-It3 at www.simon-coombs.com

MiniFireDragon
08-26-2006, 08:49 AM
That is where the file I/O handlers comes in in the C++ language. You can specify an exact location of where to get your ini file, or generally windows starts by looking in the directory the plug in is stored in then goes up the chain of set directories in lightwave (aka system32 and the like).

BloodQuest
08-26-2006, 01:58 PM
But that's the thing, because a plugin is called by LightWave with a path, Windows doesn't look in that folder - it starts at the root of the current drive.

So, if my plugin is at

D:\LightWave_90\Plugins\Third-Party\MyPlugin.p

and I write to just "MyPlugin.ini", it ends up in the root, as D:\MyPlugin.ini.

Simon

BloodQuest
08-26-2006, 03:04 PM
Okay so I found GetCommandLine() which returns the path I used to run LW itself:

D:\LightWave_85\Programs\lightwav.exe -cD:\LightWave_85\Configs

There's GOT to be something similar for a .dll...

Pretty Please?

Simon

Jarno
08-26-2006, 08:18 PM
You are after the GetModuleFileName() Win32 function. Use it in the DllMain() to get the path of the DLL:



char modulepath[512];

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
GetModuleFileName((HMODULE)hModule, modulepath, 512);



---JvdL---

BloodQuest
08-27-2006, 02:47 AM
Jarno, thank you so much!

I'm not sure I completely understand it yet, but it works!

Cheers,

Simon