Article View: borland.public.cppbuilder.nativeapi
Article #1409Re: Explicit link to DLL, problem in BCB but not in MSVC
From: Eliot Frank
Date: Mon, 20 Aug 2007 17:13
Date: Mon, 20 Aug 2007 17:13
34 lines
2112 bytes
2112 bytes
Boris Epel wrote:
>
> .h:
> typedef int32 (__CFUNC *DAQmxGetChanType_f) (TaskHandle taskHandle,
> const char channel[], int32 *data);
> .c:
> HINSTANCE handle = LoadLibrary(_library);
> DAQmxGetChanType_f DAQmxGetChanType = (DAQmxGetChanType_f)
> GetProcAddress(handle, "DAQmxGetChanType");
> ...
>
You are not checking whether handle returned by LoadLibrary is valid,
nor if GetProcAddress succeeds. I suspect that DAQmxGetChanType is
getting set to NULL, so your call results in the AV you are seeing.
It's possible that DAQmxGetChanType is not supported by all versions of
the NIDAQmx API which is why it fails on some machines (Do you have the
same version installed on all your machines?)
It's good programming practice to check the result of all system calls
even though this is a pain, e.g.,
HINSTANCE handle = LoadLibrary(_library);
if (handle) {
DAQmxGetChanType_f DAQmxGetChanType =
(DAQmxGetChanType_f)GetProcAddress(handle, "DAQmxGetChanType");
if (DAQmxGetChanType == NULL)
ShowMessage ("DAQmxGetChanType not found!");
} else {
// check result of GetLastError
// use FormatMessage to obtain human readable error info
}
-Eliot
Technical Details
Message-ID:
<46c9cbe3$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<46c0a633$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,1e7567d9fb04a084 X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Date: Mon, 20 Aug 2007 13:13:51 -0400 From: Eliot Frank <eliot_h_frank@yahoosky.comski> User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Explicit link to DLL, problem in BCB but not in MSVC References: <46c0a633$1@newsgroups.borland.com> In-Reply-To: <46c0a633$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 18.125.1.130 Message-ID: <46c9cbe3$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1187630051 18.125.1.130 (20 Aug 2007 10:14:11 -0700) Lines: 34 Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail