cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

griffin2000
Journeyman III

Anyone been able to dynamically link OpenCL

For our project we need to be able to dynamically link OpenCL (so our application can compiled and run on machines without OpenCL installed on them, and only use it if its there).

I'm trying to dynamically load and run the DLL (I've tried this on Stream SDK 2.01 on windows Xp and Windows 7, using VS2008) using code like that shown below to dynamically link and run OpenCL.  But I get an ESP stack check execption like this one when I try and run the retreived function pointer:

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.  This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

 

I've tried various combinations of calling convention to no avail.  Has anyone sucessfully done this ?  Is there a particular compile setting, pragma, service pack, or something else I need to do this ?

 

 

 

#include "Windows.h" #include "CL/cl.h" typedef CL_API_ENTRY cl_int CL_API_ENTRY (*clGetPlatformIDsCBType) ( cl_uint num_entries, cl_platform_id * platforms, cl_uint * num_platforms) CL_API_SUFFIX__VERSION_1_0; int main(int argc, char* argv[]) { cl_uint numPlatforms; HMODULE pOpenCLLib=LoadLibrary("OpenCL.dll"); clGetPlatformIDsCBType clGetPlatformIDsCB=(clGetPlatformIDsCBType) GetProcAddress(pOpenCLLib,"clGetPlatformIDs"); ( clGetPlatformIDsCB(0, NULL, &numPlatforms) ); return 0; }

0 Likes
2 Replies
chris244
Journeyman III

I think you made a mistake in your function pointer typedef, it should be:

typedef CL_API_ENTRY cl_int CL_API_CALL (*clGetPlatformIDsCBType) (

0 Likes

Thanks.  That did the trick, my bad.   Though to compile in VS2008 the CL_API_CALL had to be inside the bracket:

typedef CL_API_ENTRY cl_int  (CL_API_CALL*clGetPlatformIDsCBType) (

0 Likes