Re: [問題] 關於FARPROC及GetProcAddress的問題
※ 引述《slgn0129 (緣由天定分在人為)》之銘言:
: ( *[1m *[m 為色碼,可以按 Ctrl+V 預覽會顯示的顏色 )
: ( 未必需要依照此格式,文章條理清楚即可 )
: 遇到的問題: (題意請描述清楚)
: HINSTANCE hDLL = LoadLibrary(TEXT("libGLESv2"));
: FARPROC p2 = GetProcAddress(hDLL,"glCompileShader");
: void (*p)(GLuint);
: p = (void (*) (GLuint)) p2;
: p(shader);
: hDLL有找到位址
: 但是p2卻是0x00000000
: 所以p就跟p2一樣
: 猜想可能是格式問題 但是不知道怎麼下手修改
: 希望得到的正確結果:
: 能抓到p2的位址
: 程式跑出來的錯誤結果:
: 存取違規(p=0x00000000)
: 開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux)
: VS2005
: 有問題的code: (請善用置底文標色功能)
: FARPROC p2 = GetProcAddress(hDLL,"glCompileShader");
: 補充說明:
: 如果有什麼應該要提供的資訊 小弟沒有提供的
: 請各位前輩說一下
: 請謝
給原po, 你的作法應該是可以的, 下面我貼一段code....
從PowerVR裡的Training 2裡的HelloTriangle一小段....
==
GLuint uiFragShader, uiVertShader; /* Used to hold the fragment and vertex shader handles */
GLuint uiProgramObject; /* Used to hold the program handle (made out of the two previous shaders */
// Create the fragment shader object
uiFragShader = glCreateShader(GL_FRAGMENT_SHADER);
// Load the source code into it
glShaderSource(uiFragShader, 1, (const char**)&pszFragShader, NULL);
/* 原po的code, 加一個__stdcall的轉型以符合.h/.lib/.dll的定義 */
HINSTANCE hDLL = LoadLibrary(TEXT("libGLESv2"));
FARPROC p2 = GetProcAddress(hDLL,"glCompileShader");
void (__stdcall *p)(GLuint);
p = (void (__stdcall *) (GLuint)) p2;
p(uiFragShader);
// Compile the source code
// glCompileShader(uiFragShader);
==
所以問題又回到原點了, 為什麼原po的GetProcAddress()會失敗啊?_?
--
Edit:
為了不佔用版面, 小弟把第二段codes給貼在同一篇裡....
GLuint LoadShader ( GLenum type, const char *shaderSrc )
{
/* 原po的code, 加一個__stdcall的轉型以符合.h/.lib/.dll的定義 */
HINSTANCE hDLL = LoadLibrary(TEXT("libGLESv2"));
FARPROC p2 = GetProcAddress(hDLL,"glCompileShader");
void (__stdcall *p)(GLuint);
GLuint shader;
GLint compiled;
// Create the shader object
shader = glCreateShader ( type );
if ( shader == 0 )
return 0;
// Load the shader source
glShaderSource ( shader, 1, &shaderSrc, NULL );
/* 原po的code, 只是舊的C語言宣告一定要在{}最前面, 故分開之. */
p = (void (__stdcall *) (GLuint)) p2;
p(shader);
// Compile the shader
// glCompileShader ( shader );
==
這樣子的code是可以build得過同時跑得出來的....
所以原po你要不要再檢查一下其他地方有啥不對@_@"
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.134.41.4
→
12/04 13:03, , 1F
12/04 13:03, 1F
→
12/04 13:07, , 2F
12/04 13:07, 2F
※ 編輯: VictorTom 來自: 220.134.41.4 (12/04 14:17)
推
12/04 14:21, , 3F
12/04 14:21, 3F
→
12/04 14:22, , 4F
12/04 14:22, 4F
→
12/04 14:22, , 5F
12/04 14:22, 5F
→
12/04 14:22, , 6F
12/04 14:22, 6F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 5 篇):