problemes pour creer une DLL
voila je suis un vrai débutant en C C# mais j'ai vraiment de besoin de créer une DLL que je pourrais utiliser en ruby pour changer la resolution de mon ecran.
bon, trouver une fonction pour changer la resolution n'a pas été trop difficile, je me suis alors dis que faire une DLL avec cette fonction serait simple. Je me suis trompé :?
lorsque j'essaie de compiler ma dll j'ai un message d'erreur du genre,
function `int SetResolution(int, int, int)' definition is marked dllimport.
okay, c'est sympa de me le dire mais moi, le C j'y connais que dalle.
alors voilà mon code, en esperant que quelqu'un puisse m'aider.
dllmain.c
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
|
#include "dllmain.h"
#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
DLLIMPORT int SetResolution(int width, int height, int fullscreen)
{
DEVMODE dm;
ZeroMemory(&dm, sizeof(dm));
dm.dmSize = sizeof(dm);
if (0 != EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm))
{
dm.dmPelsWidth = width;
dm.dmPelsHeight = height;
long lRet = ChangeDisplaySettings(&dm, fullscreen);
if (DISP_CHANGE_SUCCESSFUL != lRet)
{
}
}
}
BOOL APIENTRY DllMain (HINSTANCE hInst,
DWORD reason,
LPVOID reserved )
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return TRUE;
} |
dllmain.h
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#ifndef _DLL_H_
#define _DLL_H_
#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else
# define DLLIMPORT __declspec (dllimport)
#endif
DLLIMPORT int SetResolution(int, int, int);
#endif |
main.c
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main(int argc, char *argv[])
{
HINSTANCE mydll;
typedef int(*DLLSTART)();
DLLSTART fonction;
mydll = LoadLibrary("DLL.dll");
fonction = (DLLSTART) GetProcAddress(mydll, "SetResolution");
fonction();
FreeLibrary(mydll);
return 0;
} |