12-12-2006 02:34 PM
12-13-2006 01:53 AM
@T-Hawk wrote:
Background:I have written a DLL using C++ and I am accessing this DLL from LabVIEW using the Call Library Function. One specific function I have in my DLL opens a file (which is passed in as a parameter) and operates on the data. I need to specify the filename using LabVIEW, so I have a "path" control on my front panel. After converting this path to a string, I pass it into my DLL as a Cstr Pointer.Problem:It appears that I am perfectly capable of opening files that are contained in the same directory as the LabVIEW vi. If I try to access an exact replica of the same file in a different directory, LabVIEW chokes and says there's an error in the DLL function that I am using. Even more strange, I had a duplicate folder that contained the same dll, and when I would copy a file into the duplicate folder and access it through the ORIGINAL vi, LabVIEW wouldn't crash. Not sure if that's helpful or not.Things I've tried:I noticed that the path control in LabVIEW has backslashes instead of forward slashes. I figured this might be a problem since the "\" character in c++ is to denote special characters. So I converted all "\" to forward slashes. Still had the same problem.Any advice would help. Thanks a lot!
Are you working on Unix!!!! Windows uses always backslashes for path separators. You do not need to escape the backslashes. That is only necessary for the C compiler in order to know that it should use the actual \ ASCI code instead of trying to interpret the following character(s) as backslash codes. Once the C compiler has processed the C source file a single backslash is placed into memory just as what LabVIEW passes to your DLL.
Are you using absolute file paths? Relative file paths always have the difficulty to where they reference. Under Windows and the ANSI C library there is a concept of a current directory that is maintained by Windows on a per process base. It is used by most ANSI C functions as base when given a relative path as input. But under Windows this makes not much sense since various Windows APIs will reset that current directory path such as File dialogs and similar.
I guess once you have made sure that above comments are correct the next step would be to debug into your C source code with your source level debugger of your choice. 99.9999999999999% chance that you do something wrong in your C code, which is also my own experience too.
Rolf Kalbermatter
12-13-2006 09:27 AM
I am in Windows, not Unix.
I am using absolute paths. In LabVIEW, the path control automatically selects the absolute path. If you work with LabVIEW, you could verify this for me and make sure that's correct.
Actually, I have debugged my C code to no end. If I run my C DLL using a C console application, I can pass any file path I want to and it always works! That's what's so frustrating. That tells me that there's something causing my VI and my DLL to not play nice.
Can you think of any reason why it appeared to work when I specified a filename contained in a distant folder that contained a copy of the dll?
Thanks for your help!
12-13-2006 12:12 PM
12-13-2006 12:52 PM
12-13-2006 01:09 PM
@T-Hawk wrote:Well, if I create a new file inside the function that I'm calling with LabVIEW, it does NOT always show up in the home directory...it actually creates the file in the same directory as the path control.Is there a possibility that the path control somehow changes the directory in which the program is running? I know that's crazy...so I'm sure you're laughing at the stupidity of that suggestion. I'm just so out of ideas for this crazy problem! If I'm not presenting this to you very well, please feel free to throw in the towel.T
12-13-2006 01:20 PM
#ifdef
FILEIO_EXPORTS#define
FILEIO_API __declspec(dllexport)#else
#define
FILEIO_API __declspec(dllimport)#endif
#include
"stdafx.h" //don't think this header does much. MSV added it for me#include "FileIO.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
//Example of my DLL function
FILEIO_API
void OpenFile(char *filename){ //opens file, makes use of its contents
}
Sorry about the weird formatting from the copy/paste. That's basically ALL I'm doing with the DLL. Does this look like I'm missing something to you?
12-13-2006 04:42 PM
@TonP wrote:
Hi T-Hawk,
I think I know what happens, if you browse to a folder and select a file there, LV set that as the home directory, BUT I COULDN'T VERIFY THIS
Have you set your dll reentrant (thread safe?)
Ton
Actually setting of the current directory is a feature of the Windows file dialog as mentioned in my earlier answer. Nothing LabVIEW would need to do for that in contrary, LabVIEW would need to do something specific in order to not have the current directory changed by the file dialog. But since LabVIEW itself does not use the current directory maintained by the OS for anything it simply doesn't care.
Rolf Kalbermatter
12-14-2006 01:11 PM
I'm sorry, I don't know if I understand what that means. If LabVIEW "doesn't care" what directory is considered the "home" directory, why am I having the problem that I am having and what other steps should I be taking to solve this? I'm convinced that the DLL is dependent in some way to where the home directory is set, so I'm wondering if this is the problem.
If nothing else...you said that LabVIEW had to do something special to NOT change the home directory. Any idea about what needs to be done, or how I can figure out how to make that change?
Thanks!
T
12-14-2006 03:57 PM - edited 12-14-2006 03:57 PM
You can't change LabVIEW itself since you do not have the source code. Also the term home directory is a bit misleading here. What probably is the problem here has more to do with the so called current directory, an artefact from the standard C library implementation and also somehow present in Windows, though applications depending on that will very likely run into all kind of problems. Several Windows APIs will change that current directory including the Windows file dialog when you select a file and close the dialog with OK. But this problem only can occur if you use low level system functions or standard C library functions with relative file names. No function receiving a valid absolute path should rely in any way on the current directory.
@T-Hawk wrote:
I'm sorry, I don't know if I understand what that means. If LabVIEW "doesn't care" what directory is considered the "home" directory, why am I having the problem that I am having and what other steps should I be taking to solve this? I'm convinced that the DLL is dependent in some way to where the home directory is set, so I'm wondering if this is the problem.
If nothing else...you said that LabVIEW had to do something special to NOT change the home directory. Any idea about what needs to be done, or how I can figure out how to make that change?
Thanks!
T
Message Edited by rolfk on 12-14-2006 10:59 PM