Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #5165 > unrolled thread

Dynamic DLL access

Started byKai Michael Poppe <kmpams@gmail.com>
First post2013-04-27 09:11 +0000
Last post2013-04-29 02:03 -0700
Articles 6 — 4 participants

Back to article view | Back to comp.lang.clipper.visual-objects


Contents

  Dynamic DLL access Kai Michael Poppe <kmpams@gmail.com> - 2013-04-27 09:11 +0000
    Re: Dynamic DLL access "Wolfgang Riedmann" <wriedmann@gmail.com> - 2013-04-27 14:51 +0200
      Re: Dynamic DLL access Kai Michael Poppe <kmpams@gmail.com> - 2013-04-27 16:13 +0000
        Re: Dynamic DLL access "Wolfgang Riedmann" <wriedmann@gmail.com> - 2013-04-27 22:19 +0200
      Re: Dynamic DLL access Malcolm G <malcolm-news2012delete@delete.jobstream.com> - 2013-04-29 09:21 +0100
    Re: Dynamic DLL access Mathias <mathias.hakansson@consultec.se> - 2013-04-29 02:03 -0700

#5165 — Dynamic DLL access

FromKai Michael Poppe <kmpams@gmail.com>
Date2013-04-27 09:11 +0000
SubjectDynamic DLL access
Message-ID<klg4ng$r1h$1@dont-email.me>
Hi NG!

I was just wondering. In C# it's possible to just [DllImport("abc.dll", 
EntryPoint="something")] without the DLL being required to be in the same 
directory as the binary since one can use SetDllDirectory(lpPathName) from 
Kernel32 DLL to set the search directory for any imported Dll function.

Is there any possibility to get this working in VO as well? I tried adding 

_DLL FUNCTION _SetDllDirectory(lpPathName AS STRING) AS LOGIC 
PASCAL:KERNEL32.SetDllDirectoryA

to my DLL, but every addition of a _DLL FUNCTION that references a DLL 
that is not in the same directory as the DLL that has _SetDllDirectory in 
it, results in an DllNotFoundException being thrown.

Anybody suggestions?

Thanks!

Kai

[toc] | [next] | [standalone]


#5166

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2013-04-27 14:51 +0200
Message-ID<au1vu0Fr4cpU1@mid.individual.net>
In reply to#5165
Hi Kai,

> Is there any possibility to get this working in VO as well? I tried
> adding
> 
> _DLL FUNCTION _SetDllDirectory(lpPathName AS STRING) AS LOGIC 
> PASCAL:KERNEL32.SetDllDirectoryA
> 
> to my DLL, but every addition of a _DLL FUNCTION that references a
> DLL that is not in the same directory as the DLL that has
> _SetDllDirectory in it, results in an DllNotFoundException being
> thrown.

in VO, the DLL must not be in the same directory as the executable, but
must be found in the path.

I'm using many C dlls referenced with _dll function statements, and
normally, on deployment, I keep them in the same directory as the
executable.
On my development machine, they are never in the executable directory.

Wolfgang

-- 

[toc] | [prev] | [next] | [standalone]


#5167

FromKai Michael Poppe <kmpams@gmail.com>
Date2013-04-27 16:13 +0000
Message-ID<klgtf2$lsm$1@dont-email.me>
In reply to#5166
> in VO, the DLL must not be in the same directory as the executable, but
> must be found in the path.

Hi Wolfgang!

By "path" you mean the environment variable PATH?

Regards

Kai

[toc] | [prev] | [next] | [standalone]


#5168

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2013-04-27 22:19 +0200
Message-ID<au2q6fF2hftU1@mid.individual.net>
In reply to#5167
Hi Kai,

> > in VO, the DLL must not be in the same directory as the executable,
> > but must be found in the path.
> 
> Hi Wolfgang!
> 
> By "path" you mean the environment variable PATH?

yes. This is standard Windows behaviour.

Wolfgang



-- 

[toc] | [prev] | [next] | [standalone]


#5169

FromMalcolm G <malcolm-news2012delete@delete.jobstream.com>
Date2013-04-29 09:21 +0100
Message-ID<04qft.81051$z82.44236@fx07.fr7>
In reply to#5166
On 27/04/2013 13:51, Wolfgang Riedmann wrote:
> Hi Kai,
> 
>> Is there any possibility to get this working in VO as well? I tried
>> adding
>>
>> _DLL FUNCTION _SetDllDirectory(lpPathName AS STRING) AS LOGIC 
>> PASCAL:KERNEL32.SetDllDirectoryA
>>
>> to my DLL, but every addition of a _DLL FUNCTION that references a
>> DLL that is not in the same directory as the DLL that has
>> _SetDllDirectory in it, results in an DllNotFoundException being
>> thrown.
> 
> in VO, the DLL must not be in the same directory as the executable, but
> must be found in the path.
> 
> I'm using many C dlls referenced with _dll function statements, and
> normally, on deployment, I keep them in the same directory as the
> executable.
> On my development machine, they are never in the executable directory.

From memory there are 3 important components
	the exe path
	the current path
	the current windows environment PATH

MS docs on the search order
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682586%28v=vs.85%29.aspx

[toc] | [prev] | [next] | [standalone]


#5170

FromMathias <mathias.hakansson@consultec.se>
Date2013-04-29 02:03 -0700
Message-ID<014b8e45-6a0b-4b2e-8ddf-030fb8ad0e3d@googlegroups.com>
In reply to#5165
See a small sample on how to do this in VO below. Define the function whithout body and define a function pointer to it. Load the dll, set the pointer, and you can call the function. In this sample I register an Axit function so that I can unload the dll when my class is collected by the garbage collector.

/Mathias

static function ObjectAdd(iobjectType as int,objectID as psz,name as psz,ispanYear as int) as int pascal
	return 0

class XorBase51
	protect hinst as ptr
	protect pObjectAdd as ObjectAdd	ptr


method Init(ftg,path) class XorBase51
	self:hinst := LoadLibrary(psz("xorbase5.dll"))

	if self:hinst == null
		InfoBox{,"XorBase5","Failed to load xorbase5.dll"}:Show()
		self:failed := true
		
		return self
	endif

	self:pObjectAdd	:= GetProcAddress(self:hinst,psz("ObjectAdd"))

	RegisterAxit(self)
	
	return self

method AddObject(iType,sNo,sName,dStart,dEnd,lOneYear) class XORBase51
	local iRet as int
	
	iRet := call(pObjectAdd,iType,String2Psz(sNo),String2Psz(sName),iif(lOneYear,0,1))
		
	return (iRet == DBOK)

method Axit() class XorBase51
	return FreeLibrary(self:hinst)

/Mathias

Den lördagen den 27:e april 2013 kl. 11:11:12 UTC+2 skrev Kai Michael Poppe:
> Hi NG!
> 
> 
> 
> I was just wondering. In C# it's possible to just [DllImport("abc.dll", 
> 
> EntryPoint="something")] without the DLL being required to be in the same 
> 
> directory as the binary since one can use SetDllDirectory(lpPathName) from 
> 
> Kernel32 DLL to set the search directory for any imported Dll function.
> 
> 
> 
> Is there any possibility to get this working in VO as well? I tried adding 
> 
> 
> 
> _DLL FUNCTION _SetDllDirectory(lpPathName AS STRING) AS LOGIC 
> 
> PASCAL:KERNEL32.SetDllDirectoryA
> 
> 
> 
> to my DLL, but every addition of a _DLL FUNCTION that references a DLL 
> 
> that is not in the same directory as the DLL that has _SetDllDirectory in 
> 
> it, results in an DllNotFoundException being thrown.
> 
> 
> 
> Anybody suggestions?
> 
> 
> 
> Thanks!
> 
> 
> 
> Kai

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.clipper.visual-objects


csiph-web