C# PINVOKE error

I have a 64bit machine, and have installed the 64bit drivers, and am using the 64bit dlls, and have set the c# project to 64bit. However, the libFrontPanel-pinv.dll does not load properly when it is meant to, and instead throws the following error:

“An attempt was made to load a program with an incorrect format.”

when i do the following:

okCFrontPanel dev = new okCFrontPanel();

The frontpanel software is working, and i can program the FPGA with this as well as change clocks, so i know the driver is working.

Any ideas?


I have fixed the problem, but i am not sure how i did it. I kept on reinstalling things and it magically worked.

This is a problem that we have had many times with different versions of frontpanel.


You need to install the Frontpanel for the target machine’s platform.
If you install an x86 Frontpanel distro, you can only use the x32 API and the installed x64 dll’s are worthless.
If you install an x64 Frontpanel distro, you can only use the x64 API and the installed x32 dll’s are worthless.

I have had the same issues because I am developing on a x64 machine but deploying to a x86 machine. Main thing I have found out is that is you are on a x64 machine, you need to do a clean install of the x64. If I am going to be compiling for the x86 machine, uninstall the x64 distro, install the x86 distro, change the links to the x86 dll’s, and you are off. Same process to go back to the x64 machine. In true engineering format I don’t know what the issue is, but this hack works for me.

Hi there,

The DLLs are valid for both 64-bit and 32-bit in the x64 distribution of FrontPanel. Windows 32-bit cannot run 64-bit applications. The distribution downloaded should match the host computer. To target a different computer, use the DLL files appropriate for the target computer. You can build 32-bit applications on a 64-bit machine with the 64-bit FrontPanel distribution as long as the DLL files you are using come from the Win32 folder in any of the language-specific API directories. For example, use the files from API/Csharp/Win32 for a 32-bit C# application. If you are using an IDE, you may also need to change your project’s target application.

For more information, please refer to the Application Programmer’s Interface section of the FrontPanel User’s Manual: http://assets00.opalkelly.com/library/FrontPanel-UM.pdf


Have you tried this? I have spent 3 days troubleshooting this trying all permutations. At first I thought it was a 4.4.1 vs a 4.4.2 issue because the install file path changed. I should mention that I am using Win7 and the C# API.

I have not been able to get the x64 install of Front Panel to build a x86 application using the 32bit drivers and then run on a x86 machine that has a x86 install of Front Panel.

I have been able to get the x86 install of Front Panel to build a x86 application using the 32bit drivers and then run on a x86 machine that has a x86 install of Front Panel.