Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile a C DLL for 64 bit with Visual Studio 2010?

I have a DLL written in C in source code. This is the code for the General Polygon Clipper (in case you are interested). I'm using it in a C# project via the C# wrapper provided on the homepage. This comes with a precompiled DLL.

Since switching to a 64bit Development machine with Visual Studio 2010 and Windows 7 64 bit, the application won't run anymore. This is the error I get:

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

This is because of DLLImporting the 32bit gpc.dll, as I have gathered from stuff found on the web.

I assume this will all go away if I recompile the DLL to 64bit, but can't for the love of me figure out how to do so. My C skills are basic, in that I can write a C program with the GNU tools, but have no experience with various compilers / processors / IDEs etc.

I believe I could port this to C#. By that I mean I trust myself to actually pull it off. But I'd prefer not to, since it is a lot of work that I'd prefer a compiler to do for me ;)

like image 342
Daren Thomas Avatar asked Jun 17 '10 09:06

Daren Thomas


People also ask

How do I create a 64-bit DLL in Visual Studio?

Choose the Configuration Manager button to open the Configuration Manager dialog box. In the Active Solution Platform drop-down list, select the <New...> option to open the New Solution Platform dialog box. In the Type or select the new platform drop-down list, select a 64-bit target platform.

How do you call a 64-bit DLL from a 32-bit application?

Solution. You cannot call a 64-bit DLL from 32-bit LabVIEW. This is a limitation of 64-bit Windows, which does not support mixed 64-bit/32-bit processes. The recommended solution is to recompile the DLL from the source code for a 32-bit target architecture.

How do I change my Visual Studio application from 32-bit to 64-bit?

Open the 32-bit project in Visual Studio 2008. In the file menu, click Build and select Configuration Manager. Pull down the drop-down under “Active solution platform” which currently displays “Win32” and select New. In the drop-down for “Type or select the new platform”, select “x64”.


1 Answers

It could be as easy as creating a new platform:

  • open property pages of project (ALT+ENTER)
  • choose platform x64 in dropdown menu in top-right corner
    • if the platform does not already exist, create a new one
  • rebuild
    • make sure you are checking the right artefacts when built, as you now probably have a different output directory.
like image 191
Daren Thomas Avatar answered Nov 14 '22 23:11

Daren Thomas