?
Hallo!
Ich bin gerade dabei mit Visual C++ (ohne MFC) eine DLL zu schreiben, die ich dann in ein Visual Basic-Programm einbinden will.
Das Einbinden und Aufrufen der Funktionen der DLL funktioniert auch soweit, aber jetzt kommt mein Problem:
In einer Funktion der DLL will ich eine andere Datei mit fopen öffnen, aber jedesmal, wenn ich diese Funktion vom VB-Programm aus aufrufe stürzt das Programm ab.
Ich habe die fopen-Funktion auch schon in nem VC++ - Konsolenprogramm ausprobiert, und da funktionierts ohne Probleme.
Ich weis grad echt nicht was ich falsch mache. Vielleicht kann mir hier jemand helfen.
Hier ist der Code der DLL:
// Schnittstelle.cpp : Definiert den Einsprungpunkt für die DLL-Anwendung.
//
#include "stdafx.h"
//#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <windows.h>
#include <o2dpcicdll.h>
#include <pcicdll_errorcodes.h>
//#include <malloc.h>
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
extern "C" __declspec(dllexport) int __stdcall WINAPI SendApplication(unsigned int con_id, char *filename, int app_id)
{
struct stat fileinfo;
int size, retval=0;
char *buffer;
retval = con_id;
FILE *fp = fopen("C:\\SuchEinsen.O2D", "rb"); <-- hier stürzt das Programm ab
fclose(fp);
/*
// get size of file
fstat(fileno(fp), &fileinfo);
size = fileinfo.st_size;
// allocate buffer and read file contents to buffer
buffer = (char *)malloc(size);
fread(buffer, 1, size, fp);
fclose(fp);
// load the application to the device
retval = O2dSendApplication(con_id, buffer, size, 1, NULL);
free(buffer);
// log_retval("O2dSendApplication() returns %d\n", retval);
*/
return retval;
}
void main()
{}
und hier ist der Code des VB-Programms
Private Declare Function SendApplication Lib "Schnittstelle.dll" Alias "_SendApplication@12" _
(ByVal con_ID As Integer, ByVal Filename As String, ByVal app_id As Long) As Long
End Sub
Private Sub Command6_Click()
Dim errorcode As Long
Dim Dateiname As String
Dim Appnr As Long
Appnr = 2
Dateiname = "SuchSechsen.O2D"
errorcode = SendApplication(ConID, Dateiname, Appnr)
Label6.Caption = errorcode
End Sub
Private Sub Label4_Click()
End
End Sub