loadlibrary netapi32 32bit versus 64bit

  • Follow


I have a 32 bit application which works perfectly until I try to run it on 
a Windows 2008R2 64 bit server.

The line:
   DLLHandle = LoadLibrary("netapi32.dll");
always returns 0.

Static linking netapi32 also fails, but loadlibrary with kernel32 works.

I don't understand while the loadlibrary fails, there is a 
c:\Windows\SysWOW64\netapi32.dll
and looking at its exports, it has the right functions even.

I can't change the code to 64 bit due to other libraries it has to use. 
Any suggestionts?

Erick


Erick Engelke                                           erick@uwaterloo.ca
Director                                                          PHY-3013
Engineering Computing                                (519) 885-1211 x35893
University of Waterloo                  http://www.eng.uwaterloo.ca/~erick

0
Reply erick141 (6) 11/1/2010 4:51:32 PM


On Mon, 1 Nov 2010, Erick Engelke wrote:
>
> I have a 32 bit application which works perfectly until I try to run it on a 
> Windows 2008R2 64 bit server.
>
> The line:
>  DLLHandle = LoadLibrary("netapi32.dll");
> always returns 0.
>
> Static linking netapi32 also fails, but loadlibrary with kernel32 works.
>
> I don't understand while the loadlibrary fails, there is a 
> c:\Windows\SysWOW64\netapi32.dll
> and looking at its exports, it has the right functions even.
>
> I can't change the code to 64 bit due to other libraries it has to use. Any 
> suggestionts?

Also, the language is Delphi, which only produces 32 bit binaries.

Erick
0
Reply Erick 11/1/2010 5:00:53 PM


Hi Erick,

check this out:

http://www.dnjonline.com/article.aspx?id=jun07_access3264

regards

K.

"Erick Engelke"  schrieb im Newsbeitrag 
news:20101101130021.K49361@engmail.uwaterloo.ca...



On Mon, 1 Nov 2010, Erick Engelke wrote:
>
> I have a 32 bit application which works perfectly until I try to run it on 
> a Windows 2008R2 64 bit server.
>
> The line:
>  DLLHandle = LoadLibrary("netapi32.dll");
> always returns 0.
>
> Static linking netapi32 also fails, but loadlibrary with kernel32 works.
>
> I don't understand while the loadlibrary fails, there is a 
> c:\Windows\SysWOW64\netapi32.dll
> and looking at its exports, it has the right functions even.
>
> I can't change the code to 64 bit due to other libraries it has to use. 
> Any suggestionts?

Also, the language is Delphi, which only produces 32 bit binaries.

Erick 

0
Reply iso 11/2/2010 3:32:00 PM

Hi Erick,

On 11/1/2010 5:51 PM, Erick Engelke wrote:
>
> I have a 32 bit application which works perfectly until I try to run it
> on a Windows 2008R2 64 bit server.
>
> The line:
> DLLHandle = LoadLibrary("netapi32.dll");
> always returns 0.
>
> Static linking netapi32 also fails, but loadlibrary with kernel32 works.
>
> I don't understand while the loadlibrary fails, there is a
> c:\Windows\SysWOW64\netapi32.dll
> and looking at its exports, it has the right functions even.
>
> I can't change the code to 64 bit due to other libraries it has to use.
> Any suggestionts?
>


What you try to do is entirely legal and works normally. What is the 
last error immediately after the failing call to LoadLibrary? You get 
the threads last error by calling GetLastError().


-- 
S
0
Reply Stefan 11/2/2010 4:31:27 PM


On Tue, 2 Nov 2010, Stefan Kuhr wrote:
>> DLLHandle = LoadLibrary("netapi32.dll");
>> always returns 0.
>
>
> What you try to do is entirely legal and works normally. What is the last 
> error immediately after the failing call to LoadLibrary? You get the threads 
> last error by calling GetLastError().

It's 2, ERROR file not found

It returns the same error if I copy the 32 bit DLL to the same 
subdirectory.  I suppose it could be missing one of the DLLs in its 
dependancy list, but I don't know why it would, this is a fresh install.

Erick
0
Reply Erick 11/2/2010 5:28:56 PM

You can use Dependency Walker to a) check whether any dependencies are
missing and b) check in which folder Windows searches for netapi32.dll
(using the profiling feature).

www.dependencywalker.com

Timo
-- 
www.TimoSoft-Software.de - Unicode controls for VB6
"Those who sacrifice freedom for safety deserve neither."
"Demokratie ist per Definition unsicher. Ihr Schutz entsteht aus der
�berzeugung, dass die demokratischen Kr�fte �berwiegen und sich � auf
demokratischem Wege � durchsetzen."
0
Reply Timo 11/2/2010 9:11:21 PM

Hi Erick,

On 11/2/2010 6:28 PM, Erick Engelke wrote:
>
>
> On Tue, 2 Nov 2010, Stefan Kuhr wrote:
>>> DLLHandle = LoadLibrary("netapi32.dll");
>>> always returns 0.
>>
>>
>> What you try to do is entirely legal and works normally. What is the
>> last error immediately after the failing call to LoadLibrary? You get
>> the threads last error by calling GetLastError().
>
> It's 2, ERROR file not found
>
> It returns the same error if I copy the 32 bit DLL to the same
> subdirectory. I suppose it could be missing one of the DLLs in its
> dependancy list, but I don't know why it would, this is a fresh install.
>
> Erick

Then a DLL on which netapi32 is dependent is missing. Did you mess 
around with the PATH environment variable, either for your computer or 
for your process?

And as Timo wrote, the profiling feature of depends.exe comes in handy, 
and also running Process Monitor, while your call fails.

-- 
S
0
Reply Stefan 11/3/2010 7:16:57 AM

On Wed, 3 Nov 2010, Stefan Kuhr wrote:

>> On Tue, 2 Nov 2010, Stefan Kuhr wrote:
>>>> DLLHandle = LoadLibrary("netapi32.dll");
>>>> always returns 0.
>
> Then a DLL on which netapi32 is dependent is missing. Did you mess around 
> with the PATH environment variable, either for your computer or for your 
> process?
>
> And as Timo wrote, the profiling feature of depends.exe comes in handy, and 
> also running Process Monitor, while your call fails.

I found the reason I was running into this, I was running the application 
from my network drive (where I compiled it).  Copying it to the C: drive 
caused windows to work as expected.

I didn't try searching MSDN as to why that happens.  It's not a nice 
effect, we teach our students to compile on the network drive where 
everything is backed up.

Erick
0
Reply Erick 11/3/2010 1:51:15 PM

Hi Erick,

On 11/3/2010 2:51 PM, Erick Engelke wrote:
>
> On Wed, 3 Nov 2010, Stefan Kuhr wrote:
>
>>> On Tue, 2 Nov 2010, Stefan Kuhr wrote:
>>>>> DLLHandle = LoadLibrary("netapi32.dll");
>>>>> always returns 0.
>>
>> Then a DLL on which netapi32 is dependent is missing. Did you mess
>> around with the PATH environment variable, either for your computer or
>> for your process?
>>
>> And as Timo wrote, the profiling feature of depends.exe comes in
>> handy, and also running Process Monitor, while your call fails.
>
> I found the reason I was running into this, I was running the
> application from my network drive (where I compiled it). Copying it to
> the C: drive caused windows to work as expected.
>
> I didn't try searching MSDN as to why that happens. It's not a nice
> effect, we teach our students to compile on the network drive where
> everything is backed up.
>
> Erick

This can hardly be the reason for this behaviour. Running an app from a 
network drive doesn't change the Loader behaviour. I suspect that it is 
something entirely different. Did you get any results from running your 
app inside depends.exe, as Timo suggested, or did running Process 
Monitor yield any results?

Do you have any "Security Solution" running that maybe prevents apps 
from running from a network drive if they load DLLs that do networking? 
Maybe Software Restriction Policies?

-- 
S
0
Reply Stefan 11/3/2010 3:32:47 PM

On Wed, 3 Nov 2010, Stefan Kuhr wrote:
> On 11/3/2010 2:51 PM, Erick Engelke wrote:
>>> 
>> I found the reason I was running into this, I was running the
>> application from my network drive (where I compiled it). Copying it to
>> the C: drive caused windows to work as expected.
>> 
>> I didn't try searching MSDN as to why that happens. It's not a nice
>> effect, we teach our students to compile on the network drive where
>> everything is backed up.
>>


>
> This can hardly be the reason for this behaviour. Running an app from a 
> network drive doesn't change the Loader behaviour. I suspect that it is 
> something entirely different. Did you get any results from running your app 
> inside depends.exe, as Timo suggested, or did running Process Monitor yield 
> any results?
>
> Do you have any "Security Solution" running that maybe prevents apps from 
> running from a network drive if they load DLLs that do networking? Maybe 
> Software Restriction Policies?

Actually, the depends program wouldn't load from the network drive either. 
When I copied both to the local drive, both depends and my program worked 
perfectly.

This is not as outrageous as it sounds.  Starting in Vista, exe files on 
the network drive would sometimes raise warnings before executing as 
though they had been downloaded with IE (they weren't).  The network drive 
was Samba in both cases, I haven't tried it with a Windows file server.

ERick
0
Reply Erick 11/3/2010 8:05:13 PM

Hi Erick,

On 11/3/2010 9:05 PM, Erick Engelke wrote:
> <snip>
> Actually, the depends program wouldn't load from the network drive
> either. When I copied both to the local drive, both depends and my
> program worked perfectly.
>
> This is not as outrageous as it sounds. Starting in Vista, exe files on
> the network drive would sometimes raise warnings before executing as
> though they had been downloaded with IE (they weren't). The network
> drive was Samba in both cases, I haven't tried it with a Windows file
> server.
>

Then you most probably have some security measures in place that 
restrict you (and your students) from running apps on a network drive. 
This could either be SRPs or some 3rd party solution. You might want to 
talk to your Administrators in order to create exceptions to their 
policies so your students can build their apps on the network drive.

As a side note: I would never, ever, build a binary entirely on a 
network drive, a funny coincidence is, that the only time I had to do 
this, was at university. Building on a network drive is sloooooooowwww. 
The argument that on the network drive everything is backed up is moot, 
since you don't want to back up your object files and debugging symbols, 
heck, not even your created binaries. All you want to back up is your 
source files, make files and project files, and this is what a version 
control system is there for. Set up a subversion or CVS server for your 
students, this way they learn something useful they will always be able 
to apply in their life after university and they will learn to 
differentiate what is important to back up and what is unimportant.

-- 
S
0
Reply Stefan 11/4/2010 9:27:27 AM

10 Replies
853 Views

(page loaded in 0.092 seconds)

Similiar Articles:













7/25/2012 5:50:15 PM


Reply: