Ik ben bezig met wat oefen programma's met DLL's en lib's.
Nu heb ik voorbeeld code van:
http://msdn.microsoft.com/en-us/library/ms682507(VS.85).aspx
en
http://msdn.microsoft.com/en-us/library/ms686944(VS.85).aspx
Ik snap wat dat er moet gebeuren, maar het werkt bij mij niet.
De functie GetProcAddress returned een NULL en als ik dan GetLastError doe krijg is 127 (ERROR_PROC_NOT_FOUND).
Mijn DLL heeft in de solution een eigen vcproj die ook een DLL (DLLSensor.dll) oplevert als ik deze bouw.
Mijn code:
In de cpp van mijn class DLLSensorFinder staat nu deze code:
Wat doe ik nog verkeerd?
Nu heb ik voorbeeld code van:
http://msdn.microsoft.com/en-us/library/ms682507(VS.85).aspx
en
http://msdn.microsoft.com/en-us/library/ms686944(VS.85).aspx
Ik snap wat dat er moet gebeuren, maar het werkt bij mij niet.
De functie GetProcAddress returned een NULL en als ik dan GetLastError doe krijg is 127 (ERROR_PROC_NOT_FOUND).
Mijn DLL heeft in de solution een eigen vcproj die ook een DLL (DLLSensor.dll) oplevert als ik deze bouw.
Mijn code:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
| // The myPuts function writes a null-terminated string to // the standard output device. // The export mechanism used here is the __declspec(export) // method supported by Microsoft Visual Studio, but any // other export method supported by your development // environment may be substituted. #include <windows.h> #define EOF (-1) #ifdef __cplusplus // If used by C++ code, extern "C" { // we need to export the C interface #endif __declspec(dllexport) int __cdecl myPuts(LPWSTR lpszMsg) { DWORD cchWritten; HANDLE hConout; BOOL fRet; // Get a handle to the console output device. hConout = CreateFileW(L"CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (INVALID_HANDLE_VALUE == hConout) return EOF; // Write a null-terminated string to the console output device. while (*lpszMsg != L'\0') { fRet = WriteConsole(hConout, lpszMsg, 1, &cchWritten, NULL); if( (FALSE == fRet) || (1 != cchWritten) ) return EOF; lpszMsg++; } return 1; } #ifdef __cplusplus } #endif |
In de cpp van mijn class DLLSensorFinder staat nu deze code:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| #include "DLLSensorFinder.h" #include <windows.h> #include <stdio.h> typedef int (__cdecl *MYPROC)(LPWSTR); DLLSensorFinder::DLLSensorFinder() { HINSTANCE hinstLib; MYPROC ProcAdd; BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; hinstLib = LoadLibrary(TEXT("DLLSensor")); if (hinstLib != NULL) { ProcAdd = (MYPROC) GetProcAddress(hinstLib, "myPuts"); // If the function address is valid, call the function. if (NULL != ProcAdd) { fRunTimeLinkSuccess = TRUE; (ProcAdd) (L"Message sent to the DLL function\n"); } else { DWORD error = GetLastError(); error = error; } // Free the DLL module. fFreeResult = FreeLibrary(hinstLib); } else { printf("DLL Not found"); } } |
Wat doe ik nog verkeerd?
Klus page: http://klusthuis.blogspot.com