Plug-in calling a dll on the same folder

View: New views
7 Messages — Rating Filter:   Alert me  

Parent Message unknown Plug-in calling a dll on the same folder

by Laurent LUGANS :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I created a windows 4D plug-in that is calling some functions stored in a dll.

How to get  the path to the local folder where are the plugins or the Extra folder to load the dll ?

4D 2004.7 in Client/Server


Laurent Lugans
********************************************************************** 4D Plugins hosted by 4D, Inc. http://www.4D.com/ Register for 4D Summit 2009 Today Early Bird Pricing Ends August 28th - http://www.4D.com/summit To Unsubscribe: mailto:4D-Plugins-off@... ***********************************************************************

Re: Plug-in calling a dll on the same folder

by Andreas Menzi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Try this:

GetModuleFileName(GetModuleHandle(L"MyDll.dll"), (LPWSTR)path, 256);

----- Original Message -----
Sent: Thursday, June 25, 2009 10:42 AM
Subject: Plug-in calling a dll on the same folder

Hello,

I created a windows 4D plug-in that is calling some functions stored in a dll.

How to get  the path to the local folder where are the plugins or the Extra folder to load the dll ?

4D 2004.7 in Client/Server


Laurent Lugans
********************************************************************** 4D Plugins hosted by 4D, Inc. http://www.4D.com/ Register for 4D Summit 2009 Today Early Bird Pricing Ends August 28th - http://www.4D.com/summit To Unsubscribe: mailto:4D-Plugins-off@... ***********************************************************************

RE: Plug-in calling a dll on the same folder

by simonbesner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Here’s my function:

 


From: 4D-Plugins@... [mailto:4D-Plugins@...] On Behalf Of Laurent LUGANS
Sent: 25 juin, 2009 04:43
To: 4D Plugin Talk
Subject: Plug-in calling a dll on the same folder

 

Hello,

I created a windows 4D plug-in that is calling some functions stored in a dll.

How to get  the path to the local folder where are the plugins or the Extra folder to load the dll ?

4D 2004.7 in Client/Server


Laurent Lugans

********************************************************************** 4D Plugins hosted by 4D, Inc. http://www.4D.com/ Register for 4D Summit 2009 Today Early Bird Pricing Ends August 28th - http://www.4D.com/summit To Unsubscribe: mailto:4D-Plugins-off@... ***********************************************************************

RE: Plug-in calling a dll on the same folder

by simonbesner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Here’s my function:

 

char* ReadDLLPath(void){

      char moduleDrive[4] = "";

      char modulePath[512] = "";

 

      GetModuleFileName(_hinstDLL, _dllPath, sizeof(_dllPath));

      _splitpath( _dllPath, moduleDrive, modulePath, NULL, NULL );

      _makepath( _dllPath, moduleDrive, modulePath, "NameOfYourDLLWithoutTheExtension", "dll" );

 

      return &_dllPath[0];

}

 


From: 4D-Plugins@... [mailto:4D-Plugins@...] On Behalf Of Laurent LUGANS
Sent: 25 juin, 2009 04:43
To: 4D Plugin Talk
Subject: Plug-in calling a dll on the same folder

 

Hello,

I created a windows 4D plug-in that is calling some functions stored in a dll.

How to get  the path to the local folder where are the plugins or the Extra folder to load the dll ?

4D 2004.7 in Client/Server


Laurent Lugans

********************************************************************** 4D Plugins hosted by 4D, Inc. http://www.4D.com/ Register for 4D Summit 2009 Today Early Bird Pricing Ends August 28th - http://www.4D.com/summit To Unsubscribe: mailto:4D-Plugins-off@... ***********************************************************************

RE: Plug-in calling a dll on the same folder

by simonbesner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

I forgot to tell you, _dllPath is a module variable declared this way:

 

char _dllPath[2048] = "";

 


From: 4D-Plugins@... [mailto:4D-Plugins@...] On Behalf Of Simon Besner
Sent: 25 juin, 2009 08:20
To: '4D Plugin Talk'
Subject: RE: Plug-in calling a dll on the same folder

 

Here’s my function:

 

char* ReadDLLPath(void){

      char moduleDrive[4] = "";

      char modulePath[512] = "";

 

      GetModuleFileName(_hinstDLL, _dllPath, sizeof(_dllPath));

      _splitpath( _dllPath, moduleDrive, modulePath, NULL, NULL );

      _makepath( _dllPath, moduleDrive, modulePath, "NameOfYourDLLWithoutTheExtension", "dll" );

 

      return &_dllPath[0];

}

 


From: 4D-Plugins@... [mailto:4D-Plugins@...] On Behalf Of Laurent LUGANS
Sent: 25 juin, 2009 04:43
To: 4D Plugin Talk
Subject: Plug-in calling a dll on the same folder

 

Hello,

I created a windows 4D plug-in that is calling some functions stored in a dll.

How to get  the path to the local folder where are the plugins or the Extra folder to load the dll ?

4D 2004.7 in Client/Server


Laurent Lugans

********************************************************************** 4D Plugins hosted by 4D, Inc. http://www.4D.com/ Register for 4D Summit 2009 Today Early Bird Pricing Ends August 28th - http://www.4D.com/summit To Unsubscribe: mailto:4D-Plugins-off@... ***********************************************************************

Parent Message unknown RE: Plug-in calling a dll on the same folder

by Laurent LUGANS :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This function return the path of 4D application.

On the client, the dll is in the folder with the plug-in, for example : 
C:\Documents and Settings\user\Application Data\4D\Appli.4DB_192_168_1_210\WIN4DX\

In the archives, i found this email :

Re: PA_Get4Dfolder
by Rob Laveaux Aug 24, 2006; 08:10pm :: Rate this Message: - Use ratings to moderate (?)

On 24-aug-2006, at 17:57, Simon wrote:

> Does anybody have a better solution that will allow me to retrieve  
> the Extras folder path directly in the Plugin?
Yes, have a look at this post:

http://www.4d.com/4DLINK2/4DACTION/Web_Solutions/Show.WebSTARList?
tCaseID=97807

The code example shows how to get the path to your plugin on Windows  
and load a DLL from this directory. It also explains delay loading so  
you can statically link to your DLL. This way you don't have to use  
GetProcAddress for each function.

HTH,

- Rob Laveaux

but the link doesn't work.



Here’s my function:

 

char* ReadDLLPath(void){

      char moduleDrive[4] = "";

      char modulePath[512] = "";

 

      GetModuleFileName(_hinstDLL, _dllPath, sizeof(_dllPath));

      _splitpath( _dllPath, moduleDrive, modulePath, NULL, NULL );

      _makepath( _dllPath, moduleDrive, modulePath, "NameOfYourDLLWithoutTheExtension", "dll" );

 

      return &_dllPath[0];

}
********************************************************************** 4D Plugins hosted by 4D, Inc. http://www.4D.com/ Register for 4D Summit 2009 Today Early Bird Pricing Ends August 28th - http://www.4D.com/summit To Unsubscribe: mailto:4D-Plugins-off@... ***********************************************************************

Re: Plug-in calling a dll on the same folder

by Justin Carr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Laurent

On 25/06/2009, at 11:08 PM, Laurent LUGANS wrote:

> This function return the path of 4D application.
>
> On the client, the dll is in the folder with the plug-in, for  
> example :
> C:\Documents and Settings\user\Application Data\4D\Appli.
> 4DB_192_168_1_210\WIN4DX\
>
> In the archives, i found this email :
>
>> > Does anybody have a better solution that will allow me to retrieve
>> > the Extras folder path directly in the Plugin?
>> Yes, have a look at this post:
>>
>> http://www.4d.com/4DLINK2/4DACTION/Web_Solutions/Show.WebSTARList?
>> tCaseID=97807
>>
>> The code example shows how to get the path to your plugin on Windows
>> and load a DLL from this directory. It also explains delay loading so
>> you can statically link to your DLL. This way you don't have to use
>> GetProcAddress for each function.
>>
>> HTH,
>>
>> - Rob Laveaux
>>
> but the link doesn't work.


Here is the code I use, which I think is probably based on the posting  
from the link above... I can't remember who should get credit for it -  
Rob? Danis? Thibaud? or perhaps all three!

__declspec(dllexport) BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD  
fdwReason, LPVOID lpvReserved );
char gPluginPath[_MAX_PATH] = ""; //Full path to the plugin Windows  
folder

BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID  
lpvReserved )
{
   if ( fdwReason == DLL_PROCESS_ATTACH ) {
     char *pos = NULL;

     GetModuleFileName( hinstDLL, gPluginPath, sizeof( gPluginPath ) );
     pos = strrchr( gPluginPath, '\\' );
     gPluginPath[ pos-gPluginPath+1 ] = '\0';
   }

   return TRUE;
}

BOOL LoadDLL ( char* dllName, HINSTANCE* library )
{
   char fullPath[_MAX_PATH];

   fullPath[0] = 0;
   (void *)strcpy( fullPath, gPluginPath );
   (void *)strcat( fullPath, dllName );
   (void *)strcat( fullPath, ".dll");

   *library = LoadLibraryEx( fullPath, NULL,  
LOAD_WITH_ALTERED_SEARCH_PATH );

   if ( *library == NULL ) {
     LPTSTR errorText;
     FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
                    FORMAT_MESSAGE_FROM_SYSTEM,
                    NULL,
                    (DWORD)GetLastError(),
                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                    (LPTSTR)&errorText,
                    0, NULL );
     PA_Alert( (char *)errorText );
     LocalFree( errorText );
   }
   return ( *library != NULL );
}


Then in your code you can do something like:

HINSTANCE myLibrary;

   if ( LoadDLL( "mydll", &myLibrary ) == TRUE ) {
     // Do some stuff here
   }


Regards
Justin Carr
**********************************************************************
4D Plugins hosted by 4D, Inc.                      http://www.4D.com/

    Register for 4D Summit 2009 Today
    Early Bird Pricing Ends August 28th - http://www.4D.com/summit

To Unsubscribe:                      mailto:4D-Plugins-off@...
***********************************************************************