ich habe mehrere Varianten der DLL versucht. Am Ende habe ich meinen Code ersetzt und es mit einem Einzeiler versucht und dem Grundgerüst für DLL's welches mir CodeBlocks vorgibt.
Aber das Ergebnis ist immer das gleiche.
Hier der C-Source für die DLL
Code: Alles auswählen
#include "main.h"
// a sample exported function
void DLL_EXPORT SomeFunction(const LPCSTR sometext)
{
MessageBoxA(0, sometext, "DLL Message", MB_OK | MB_ICONINFORMATION);
}
int DLL_EXPORT Summe( int a, int b) {
return a + b;
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
// attach to process
// return FALSE to fail DLL load
break;
case DLL_PROCESS_DETACH:
// detach from process
break;
case DLL_THREAD_ATTACH:
// attach to thread
break;
case DLL_THREAD_DETACH:
// detach from thread
break;
}
return TRUE; // succesful
}
Code: Alles auswählen
#ifndef __MAIN_H__
#define __MAIN_H__
#include <windows.h>
/* To use this exported function of dll, include this header
* in your project.
*/
#ifdef BUILD_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C"
{
#endif
void DLL_EXPORT SomeFunction(const LPCSTR sometext);
int DLL_EXPORT Summe( int, int);
#ifdef __cplusplus
}
#endif
#endif // __MAIN_H__
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import windll
>>> mydll = windll.LoadLibrary("PET.dll")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\python27\lib\ctypes\__init__.py", line 443, in LoadLibrary
return self._dlltype(name)
File "c:\python27\lib\ctypes\__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 193] %1 ist keine zulõssige Win32-Anwendung
>>>
Wo liegt der Fehler, bei Python oder wird die DLL falsch erstellt?
Ich Benutze die Codeblocks IDE mit MingW Unterbau und Python von Python.Org