Click here to Skip to main content
15,905,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all:
My Os is x64 sysetm.However I complier my program at "Any CPU" mode.
But I can't p/invoke any X86 or X64 dll file.
How to do that i can call X64 or X86 dll?
Thanks.

Well,
I use C# to build some GUI and some x64 image processing code(mamaged).
But I also want to call opencv function.I try to use emgu or opencvsharp to call dll file.
But i failed.
Posted
Updated 19-Aug-12 5:03am
v3
Comments
[no name] 19-Aug-12 10:52am    
Maybe you could try the clearly explaining what you are trying to do thing again...

If your dll is X64, then why not build an X64 exe, given that the DLL is tying you to that platform anyhow ?
 
Share this answer
 
Comments
wuling 19-Aug-12 19:24pm    
I have tried to build and run X64 exe, and program has some "use control" GUI. If I complier and run X64 exe, and result i get "BadImageExpection" Error. So the only way is to complier "Any CPU" Platform, and i only can debug and run this mode.
Christian Graus 19-Aug-12 20:16pm    
If your issue is with a dll that is compatible with your system, then you need to post your p/invoke code so we can help fix it.
wuling 19-Aug-12 22:31pm    
Dear Graus:
I think i can try:
Complier User control at "Any CPU" platform and don't complier at "x86" & "x64"
Complier Main program at "X64" platform and then call DLL files.
Then I will tell you the result
wuling 20-Aug-12 0:43am    
Dear Graus:The result is I can't debug at this case.The only way is:

User control Complier:"Any CPU"
Main Pogram Complier:"Any CPU"


How to call dll(X64) File?? below list is p/invoke CUDA dll file and


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;namespace CudaPinvoke{

public static class CDLL {

internal const string CUDA_DRIVER_API_DLL_NAME = "nvcuda";

[DllImport("cudadll.dll", CallingConvention = CallingConvention.Cdecl)]

public static extern CUResult addWithCuda(int[] c, int[] d, int[] a, int[] b, ushort size);

[DllImport("cudadll.dll", CallingConvention = CallingConvention.Cdecl)]

public static extern CUResult addWithCuda1(int[] d, int[] c, ushort size);

[DllImport("cudadll.dll", CallingConvention = CallingConvention.Cdecl)]

public static extern CUResult ScanWithCuda(int[] src, int[] dsc2d, int[] dsc3d, int thresholdvalue, int sdown, int sup, int height, int size);

[DllImport("cudadll.dll", CallingConvention = CallingConvention.Cdecl)]

public static extern CUResult ScanWithCuda(byte[] src, int[] dsc2d, int[] dsc3d, int thresholdvalue, int sdown, int sup, int height, int size);

[DllImport("cudadll.dll", CallingConvention = CallingConvention.Cdecl)]

public static extern CUResult ScanWithCuda(IntPtr src, int[] dsc2d, int[] dsc3d, int thresholdvalue, int sdown, int sup, int height, int size);

[DllImport("cudadll.dll", CallingConvention = CallingConvention.Cdecl)]

public static extern CUResult gpuDeviceInit(int devID);

[DllImport(CUDA_DRIVER_API_DLL_NAME)]

public static extern CUResult cuDeviceGetProperties(ref CUDeviceProperties prop, CUdevice dev);

}}

and here is emgu p/invoke to call dll


[DllImport(OPENCV_IMGPROC_LIBRARY, CallingConvention = CvInvoke.CvCallingConvention)]

public static extern void cvLaplace(IntPtr src, IntPtr dst, int apertureSize);


How to do to call dll file at "Any CPU" platform???
dear Christian Graus :
If all project setup "Any CPU" platform then i can call dll(x64) correctly.
thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900