?
Solved

What's wrong with this function?

Posted on 1999-11-11
8
Medium Priority
?
140 Views
Last Modified: 2010-04-04
I've written the following function...

////////////////////////////////////////

function MapNetworkDrive(RemoteName, LocalName: String; ReMapAtLogon: Boolean): Integer;
var
  NewMap : NetResource;
begin
  NewMap.lpRemoteName:=PChar(RemoteName);
  NewMap.lpLocalName:=PChar(LocalName);
  NewMap.lpProvider:=nil;
  If ReMapAtLogon then
    Result:=WNetAddConnection2(NewMap, nil, nil, CONNECT_UPDATE_PROFILE)
  else
    Result:=WNetAddConnection2(NewMap, nil, nil, CONNECT_TEMPORARY);
end;

////////////////////////////////////////

If I use the above code within my application (not a seperate function), it works great, but if I reference it as a function, it doesn't work.  Why not?

John.
0
Comment
Question by:Jaymol
  • 4
  • 2
  • 2
8 Comments
 
LVL 10

Accepted Solution

by:
Lischke earned 200 total points
ID: 2199967
I think the reason is because you forgot to add:

  NewMap.dwType := RESOURCETYPE_DISK;

and this structure member contains random data so it sometimes works and sometimes not.

Ciao, Mike
0
 
LVL 6

Author Comment

by:Jaymol
ID: 2199970
Edited text of question.
0
 
LVL 6

Author Comment

by:Jaymol
ID: 2199973
I'll try that Mike, but like I said - it works fine outside a function!

John.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
LVL 7

Expert Comment

by:RBertora
ID: 2199976
nil, nil -> have you tried putting a networkname and password?
Rob;-)
0
 
LVL 6

Author Comment

by:Jaymol
ID: 2199980
Rob: Thanks for the comment, but Mike's got it!  I needed to send it this...

MapNetworkDrive({path}, Chr(TmpI)+':', True)

but it wouldn't work.  With Mike's answer, it does!!!!

(It's just a program to map to the first available drive.)

Thanks Mike!
0
 
LVL 6

Author Comment

by:Jaymol
ID: 2199987
SUPER!! WONDERFUL!!!

Ta Mike.

John. (.)(.)
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2199991
Glad to help :-)

Ciao, Mike
0
 
LVL 7

Expert Comment

by:RBertora
ID: 2199994
(.)(.)
yes great!
Rob ;-)
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question