‎01-22-2026 05:07 PM
I have downloaded the Kvaser LabVIEW driver and the required Canlib sdk from Kvaser.
I am trying to run the demo that came with the Kvaser LabVIEW drivers it keeps returning the error "Can not find requested DLL".
But the DLL in question is right were the Call Library Function expects it to be.
What am I doing wrong here?
‎01-23-2026 09:02 AM - edited ‎01-23-2026 09:08 AM
I guess you are on Win64 (LV64) and trying to load a 32bit dll here?
If not check if a dependency is missing (not findable) with https://github.com/lucasg/Dependencies for canlib32.dll
‎01-23-2026 09:28 AM
@Quiztus2 wrote:
I guess you are on Win64 (LV64) and trying to load a 32bit dll here?
If not check if a dependency is missing (not findable) with https://github.com/lucasg/Dependencies for canlib32.dll
Well it is Windows 10 64 bit but I am using 32bit LabVIEW
I can't run any of that on my computer, corporate security policies will have my (you know what) in a sling.
‎01-23-2026 10:31 AM - edited ‎01-23-2026 10:33 AM
Can you confirm that "canlib32.dll" is actually a 32-bit PE executable and working?
There are a few ways to check without installing tools - there should be a PE signature ("PE\0\0") in the first 300-ish bytes. You could just read the .dll as a binary file into LabVIEW and check by hand.
To confirm the dll loading correctly at all, try loading it into a powershell environment.
I had a similar issue with 32bit executables on a 64bit host having some system directories redirected for compatibility. This might throw off the dll.
‎01-23-2026 11:26 AM
I have never used Powershell but a quick Google and tried to use the Add-Type command and get an error basically saying it does not understand the (x86) part of the path?
PS Z:\> Add-Type C:\Program Files (x86)\Kvaser\Canlib\Bin\canlib32.dll
x86 : The term 'x86' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:28
+ Add-Type C:\Program Files (x86)\Kvaser\Canlib\Bin\canlib32.dll
+ ~~~
+ CategoryInfo : ObjectNotFound: (x86:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I loaded the file into LabVIEW as a binary file and all I see besides "This program cannot be run in DOS mode" is a bunch of non-printable characters.
‎01-23-2026 12:40 PM
@RTSLVU wrote:
I have never used Powershell but a quick Google and tried to use the Add-Type command and get an error basically saying it does not understand the (x86) part of the path?
PS Z:\> Add-Type C:\Program Files (x86)\Kvaser\Canlib\Bin\canlib32.dll
x86 : The term 'x86' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:28
+ Add-Type C:\Program Files (x86)\Kvaser\Canlib\Bin\canlib32.dll
+ ~~~
+ CategoryInfo : ObjectNotFound: (x86:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I loaded the file into LabVIEW as a binary file and all I see besides "This program cannot be run in DOS mode" is a bunch of non-printable characters.
This is the relevant part:
If you switch the string view to "\ codes", this part will probably become "PE\00\00\01\4C" (the x86 marker, as per https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#coff-file-header-object-and-image )
So the file is indeed a 32bit dll. The powershell import needs quotation marks for the complete file name, like so:
Add-Type "C:\Program Files (x86)\Kvaser\Canlib\Bin\canlib32.dll"
However, Add-Type only works on .NET stuff. A binary dll needs an explicit type declaration to be loaded into powershell, which is a bit more involved: https://www.raydbg.com/2017/Call-Native-Win32-API-in-PowerShell/
So it should probably look like this (I recommend changing to the directory containing the dll with the cd command):
cd "C:\Program Files (x86)\Kvaser\Canlib\Bin\"
function ImportedCanOpenChannel {
$Signature = @"
[DllImport("canlib32.dll", EntryPoint = "canOpenChannel")]
public static extern int canOpenChannel(uint channelNumber, uint flags);
uint channel = 1;
uint flags = 0x0;
public static void CanOpenChannelExport() {
canOpenChannel(channel, flags);
}
"@
Add-Type -MemberDefinition $Signature -Name CanOpenChannelType -Namespace User_
[User_.CanOpenChannelType]::CanOpenChannelExport()
}
ImportedCanOpenChannel
This is quite the sandwich though, wrapping the import into a .NET function wrapped into a .NET type, imported and called into powershell. It might be a good idea to check if the dll exports a simpler function (like GetVersion or the like).
‎01-23-2026 12:47 PM
Have you loaded in the library?
There should be a VI and dll function to load tthe library into memory.
‎01-23-2026 01:14 PM
I don't know what this is telling me.
PS C:\Program Files (x86)\Kvaser\Canlib\Bin> function ImportedCanOpenChannel {
>> $Signature = @"
>> [DllImport("canlib32.dll", EntryPoint = "canOpenChannel")]
>> public static extern int canOpenChannel(uint channelNumber, uint flags);
>>
>> uint channel = 1;
>> uint flags = 0x0;
>>
>> public static void CanOpenChannelExport() {
>> canOpenChannel(channel, flags);
>> }
>> "@
>> Add-Type -MemberDefinition $Signature -Name CanOpenChannelType -Namespace User_
>> [User_.CanOpenChannelType]::CanOpenChannelExport()
>> }
>>
>> ImportedCanOpenChannel
Add-Type : c:\Users\searsrt\AppData\Local\Temp\ke4fuggk\ke4fuggk.0.cs(15) : An object reference is required for the
non-static field, method, or property 'User_.CanOpenChannelType.channel'
c:\Users\searsrt\AppData\Local\Temp\ke4fuggk\ke4fuggk.0.cs(14) : public static void CanOpenChannelExport() {
c:\Users\searsrt\AppData\Local\Temp\ke4fuggk\ke4fuggk.0.cs(15) : >>> canOpenChannel(channel, flags);
c:\Users\searsrt\AppData\Local\Temp\ke4fuggk\ke4fuggk.0.cs(16) : }
At line:13 char:5
+ Add-Type -MemberDefinition $Signature -Name CanOpenChannelType -N ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Except
ion
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
Add-Type : c:\Users\searsrt\AppData\Local\Temp\ke4fuggk\ke4fuggk.0.cs(15) : An object reference is required for the
non-static field, method, or property 'User_.CanOpenChannelType.flags'
c:\Users\searsrt\AppData\Local\Temp\ke4fuggk\ke4fuggk.0.cs(14) : public static void CanOpenChannelExport() {
c:\Users\searsrt\AppData\Local\Temp\ke4fuggk\ke4fuggk.0.cs(15) : >>> canOpenChannel(channel, flags);
c:\Users\searsrt\AppData\Local\Temp\ke4fuggk\ke4fuggk.0.cs(16) : }
At line:13 char:5
+ Add-Type -MemberDefinition $Signature -Name CanOpenChannelType -N ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Except
ion
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
Add-Type : Cannot add type. Compilation errors occurred.
At line:13 char:5
+ Add-Type -MemberDefinition $Signature -Name CanOpenChannelType -N ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Add-Type], InvalidOperationException
+ FullyQualifiedErrorId : COMPILER_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand
Unable to find type [User_.CanOpenChannelType].
At line:14 char:5
+ [User_.CanOpenChannelType]::CanOpenChannelExport()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (User_.CanOpenChannelType:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
PS C:\Program Files (x86)\Kvaser\Canlib\Bin>
‎01-23-2026 01:19 PM
@dkfire wrote:
Have you loaded in the library?
There should be a VI and dll function to load tthe library into memory.
I think so... There is this VI that runs at the beginning of the demo program without error
‎01-23-2026 02:24 PM
And how is that lib call setup ?