DLL Source
#include <windows.h>
#include <stdio.h>
#include "MyODBCLib.h"
EXTERN_C __declspec(dllexport) INT CountDSN ();
EXTERN_C __declspec(dllexport) VOID GetDSNNum (INT num , CHAR * Dsn,CHAR * Desc);
BOOL WINAPI __declspec(dllexport) LibMain (HINSTANCE hInst, DWORD Reason, LPVOID Reserved)
{
if(Reason==DLL_PROCESS_ATTACH)
{
return TRUE;
}
if(Reason==DLL_PROCESS_DETACH)
{
return TRUE;
}
return FALSE;
}
EXTERN_C __declspec(dllexport) INT CountDSN ()
{
PtrListaODBC * MiaLista;
int ret;
MiaLista=RecuperaListaODBC();
ret=QuantiDSN(MiaLista);
CancellaListaODBC(MiaLista);
return ret;
}
EXTERN_C __declspec(dllexport) VOID GetDSNNum (INT num , CHAR * Dsn,CHAR * Desc)
{
PtrListaODBC * MiaLista;
PtrListaODBC * app;
int ret, i;
MiaLista=RecuperaListaODBC();
app=MiaLista;
i=0;
while(app)
{
//printf("%s - %s\n", app->dsn, app->desc);
if (i==num)
{
Dsn=(char*)malloc(sizeof(char)*strlen(app->dsn));
sprintf(Dsn,app->dsn);
Desc=(char*)malloc(sizeof(char)*strlen(app->desc));
sprintf(Desc,app->desc);
}
i++;
app=app->next;
}
CancellaListaODBC(MiaLista);
}
So given this information, someone can explain why I can not get the data I want?
I changed no more scores for the entire list, but knowing how many dsn tell him to return the first list, the second etc..
Lazarus source
unit Unit1;
{$mode objfpc}{$H+}
{$ifdef unix}
{$linklib myfunc}
{$endif}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
ExtCtrls, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
PtrListaODBC=^appoggio;
Appoggio = record
dsn : array[0..255] of char;
desc : array[0..255] of char;
next: PtrListaODBC;
end;
var
Form1: TForm1;
//function GetListaDSN(MiaLista: PtrListaODBC): PChar; cdecl; external {$ifdef windows} 'ProgettoDLLODBC.dll'{$endif};
function CountDSN(): integer;stdcall; cdecl; external {$ifdef windows} 'ProgettoDLLODBC.dll'{$endif};
procedure GetDSNNum (num: integer;Dsn: PChar ;Desc: PChar);stdcall; cdecl; external {$ifdef windows} 'ProgettoDLLODBC.dll'{$endif};
implementation
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
app: PtrListaODBC;
i: integer;
valore: string;
MioDsn: Pchar;
MiaDesc: PChar;
begin
i:=CountDSN();
MioDSN:='--';
GetDSNNum(2,MioDSN,MiaDesc);
Edit1.Text:=IntToStr(i) + ' ' + MioDSN ;
end;
initialization
{$I unit1.lrs}
end.