Ich sollte aus einer DLL Datei <B>int</B>-Variable auslesen.<BR>
<B>ES KLAPPT ABER NICHT</B>
1. In der DLL Datei wird zehn mal eine Zufallzahl generiert.
<PRE>
/* MyDll.c Datei */
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
<P>
__declspec(dllexport) int zufallZahl;
<P>
int main(void) {
<P>
int i;
for(i=0; i<10; i++) {
zufallZahl = rand()%100;
_sleep(1);
}
<P>
return 0;
}
</PRE>
2) Die andere App.(MyDll_Test) sollte jetzt diese Zufallzahl aus der MyDll.dll Datei auslesen.
<PRE>
/* MyDll_Test.c Datei*/
#include <stdio.h>
#include <dos.h>
#include <windows.h>
<P>
typedef int (*MYDLLINT)(int);
MYDLLINT int_Var;
<P>
void myDll_init() {
HINSTANCE dll;
dll = LoadLibrary("MyDll");
<P>
if(dll == NULL)
printf("\n DLL nicht geladen \n");
<P>
int_Var = (MYDLLINT)GetProcAddress(dll, "zufallZahl");
<P>
if(int_Var == NULL)
printf("\n ZufallZahl nicht gelesen \n");
}
<P>
int main() {
int i;
myDll_init();
<P>
for(i=0; i<20; i++) {
printf("\n Zufallzahl aus DLL Datei %i = %i", i, int_Var);
_sleep(1);
}
<P>
return 0;
}
<PRE>
<B>FAZIT</B>
Die beiden Dateien lasen sich ohne Fehler Kompilieren -
die INT-Variable wird aber aus der DLL Datei nicht gelesen("ZufallZahl nicht gelesen") - wo liegt der Fehler ???
Besten Dank für jeden Tipp!
christine.
PS:
als Compiler benutze ich Borland(BCC 5.5) free C/C++ commandline tools.
<P>
<B>ES KLAPPT ABER NICHT</B>
1. In der DLL Datei wird zehn mal eine Zufallzahl generiert.
<PRE>
/* MyDll.c Datei */
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
<P>
__declspec(dllexport) int zufallZahl;
<P>
int main(void) {
<P>
int i;
for(i=0; i<10; i++) {
zufallZahl = rand()%100;
_sleep(1);
}
<P>
return 0;
}
</PRE>
2) Die andere App.(MyDll_Test) sollte jetzt diese Zufallzahl aus der MyDll.dll Datei auslesen.
<PRE>
/* MyDll_Test.c Datei*/
#include <stdio.h>
#include <dos.h>
#include <windows.h>
<P>
typedef int (*MYDLLINT)(int);
MYDLLINT int_Var;
<P>
void myDll_init() {
HINSTANCE dll;
dll = LoadLibrary("MyDll");
<P>
if(dll == NULL)
printf("\n DLL nicht geladen \n");
<P>
int_Var = (MYDLLINT)GetProcAddress(dll, "zufallZahl");
<P>
if(int_Var == NULL)
printf("\n ZufallZahl nicht gelesen \n");
}
<P>
int main() {
int i;
myDll_init();
<P>
for(i=0; i<20; i++) {
printf("\n Zufallzahl aus DLL Datei %i = %i", i, int_Var);
_sleep(1);
}
<P>
return 0;
}
<PRE>
<B>FAZIT</B>
Die beiden Dateien lasen sich ohne Fehler Kompilieren -
die INT-Variable wird aber aus der DLL Datei nicht gelesen("ZufallZahl nicht gelesen") - wo liegt der Fehler ???
Besten Dank für jeden Tipp!
christine.
PS:
als Compiler benutze ich Borland(BCC 5.5) free C/C++ commandline tools.
<P>
Comment