Click here to Skip to main content
15,888,169 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
It is really strange and I want to solve it :
I have 2 application built by C# ,
Scanner :
Is for scanning documents using special Dll Files built by c language .
The Second application built by C# also :
Runner Application :
is to run the Scanner application .

The Strange issue is :
IF I luanch the scanner app from the runner app an error will be generated because it doesn't find the Dll files .
So I try to copy and paste the dll files from Scanner/bin/Debug to runner/bin/debug
so the scanner runs correctly without any problems.

So I notice that the problem is Dll registration or dll link .

I tried to register the dll it fails , I tried to copy the dll to windows/system32 also it doesnot work.

I think the issue will be solved if I link the dll files while importing it>
C#
[DllImport("ScanDll.dll")]
 public static extern int IO_GetIDImage_File(int lImageType, int lCardType, int lCompressRet, string szFileOutPut);


Why if I start the scanner app from the runner app it search for the dll file inside runner/bin/debug not in scanner/bin/debug ????

Please need your expert to help me in that issue...
Posted
Updated 3-Feb-12 21:43pm
v3
Comments
Sergey Alexandrovich Kryukov 1-Feb-12 6:09am    
Do you type a code in question manually?
--SA

1 solution

This won't even compile:

C#
Process.Start("Folder1\bin\debug\app1.exe");
must be
C#
Process.Start(@"Folder1\bin\debug\app1.exe");


This is not so nice of you. Did you type manually? What is broken on your system, "Copy" or "Paste"? :-)

Also, there are no situations where hard-coded path name can be useful. You always need to calculate the path during run-time. In this case, you need a directory if your executables. This is a reliable method of finding it:
C#
string exePath =
   System.IO.Path.GetDirectoryName(
      System.Reflection.Assembly.GetEntryAssembly().Location);

There are other methods, but some of them require different libraries (like Forms) or depend on how application is hosted. This one is very universal. This is a location of the main executable module of the entry assembly of the application.

Also, you should never assume that your application working directory is the same, so you can use simple file name. The thing is: any user can start any application from any directory. Any at all. And this directory will be the working one, not the same as the executable directory. So, your work-around is absolutely not reliable.

If you have other problems, they are due to the problems in your application you launch in a child process, not yours.

—SA
 
Share this answer
 
v5
Comments
Rajesh Anuhya 1-Feb-12 6:09am    
Good answer SA
have my+5
Sergey Alexandrovich Kryukov 1-Feb-12 6:10am    
Thank you, Rajesh. How can you be so fast? :-)
--SA
Rajesh Anuhya 1-Feb-12 6:14am    
Your way of answering is different SA, you will hit the exact point where OP is doing wrong. and your sentence forming is also very good( as am not able to do that).
Sridhar Patnayak 1-Feb-12 6:09am    
Nice solution 5+
Sergey Alexandrovich Kryukov 1-Feb-12 6:10am    
Thank you, Sridhar.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900