Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Community > Tech > [programmare] C e DLL
  Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
cato
Wild boys always shine

User info:
Registered: Nov 2001
Posts: 5608 (0.65 al dì)
Location: lecco
Corso: F28
Anno: dottore
Time Online: 38 Days, 5:41:55 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
[programmare] C e DLL

mi sto avventurando nel magico mondo delle DLL.

il mio scopo è madare un array di char da un programma C a una funzione di una DLL (in delphi)

code:
#include <stdio.h> #include <windows.h> #include <string.h> typedef int (CALLBACK* LPFNDLLFUNC1)(char*); //CALLBACK* LPFNDLLFUNC1(); HINSTANCE hDLL; // Handle to DLL LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer int main (){ int a; char stringa[32]; char *s; hDLL = LoadLibrary("test.dll"); if (hDLL != NULL){ lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,"hello"); if (!lpfnDllFunc1) { // handle the error FreeLibrary(hDLL); return 1; } else { stringa[0]='a'; stringa[1]='b'; stringa[2]='a'; stringa[3]='c'; stringa[4]='o'; a=lpfnDllFunc1(stringa); printf("->%d",a); } } }



qui la dll

code:
library test; {prima prova di DLL} uses SysUtils, Classes, finestra in 'finestra.pas' {Form1}, Unit2 in 'Unit2.pas' {Form2}; function hello(stringa:array of pchar):integer; begin result:=100; writeln(stringa[1]); end; exports hello; {$R *.RES} var Form1: TForm1; begin writeln('prova'); //form1 := Tform1.Create(Nil); //form1.ShowModal; //form1.Free; end.


chiaramente non funziona.... :roll:

__________________

code:
  , ,  | | Me@Flickr  [ov0] | | my photo Blog  {| |} |@| Pallavolo La Nuova Rossa Milano --"-"--| | -------| | "If You Can't Open It, You Don't Own It"

22-02-2005 11:31
Click Here to See the Profile for cato Click Here to See the Blog of cato Click here to Send cato a Private Message Visit cato's homepage! Find more posts by cato Add cato to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
CLod
JAILED

User info:
Registered: May 2002
Posts: 2688 (0.32 al dì)
Location: una delle 2 torri
Corso: Master ICT Sec
Anno: security
Time Online: 14 Days, 23:35:35 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

bene :)

__________________
Se il pugno e' chiuso la mano e' vuota. Solo se la mano e' aperta puoi possedere tutto

22-02-2005 11:45
Click Here to See the Profile for CLod Click Here to See the Blog of CLod Click here to Send CLod a Private Message Find more posts by CLod Add CLod to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
yeah
.grande:maestro.

User info:
Registered: Nov 2003
Posts: 1644 (0.21 al dì)
Location: Cologno Monzese
Corso: Informatica Magistrale
Anno: II
Time Online: 12 Days, 21:36:41 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

1) Sei obbligato ad usare Dephi per la DLL?
2) Che problemi ti da?
3) Con che cosa compili e con che parametri?

__________________
?

22-02-2005 20:11
Click Here to See the Profile for yeah Click here to Send yeah a Private Message Find more posts by yeah Add yeah to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
cato
Wild boys always shine

User info:
Registered: Nov 2001
Posts: 5608 (0.65 al dì)
Location: lecco
Corso: F28
Anno: dottore
Time Online: 38 Days, 5:41:55 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

1)per il lato delphi no...
2)errori di memoria
3)gcc

__________________

code:
  , ,  | | Me@Flickr  [ov0] | | my photo Blog  {| |} |@| Pallavolo La Nuova Rossa Milano --"-"--| | -------| | "If You Can't Open It, You Don't Own It"

22-02-2005 20:28
Click Here to See the Profile for cato Click Here to See the Blog of cato Click here to Send cato a Private Message Visit cato's homepage! Find more posts by cato Add cato to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
yeah
.grande:maestro.

User info:
Registered: Nov 2003
Posts: 1644 (0.21 al dì)
Location: Cologno Monzese
Corso: Informatica Magistrale
Anno: II
Time Online: 12 Days, 21:36:41 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

1) proviamo prima a risolvere gli altri 2 problemi :)
2) errori di esecuzione o di compilazione? Puoi postare il testo?
3) e con che parametri?

[edit]
Nel frattempo ci ho provato anche io :) ma tutto in C

dll.c

code:
#include <windows.h> __declspec(dllexport) void printy(char *str) { MessageBox(NULL, str, "printy.dll", MB_OK); }


Compilazione della dll:
gcc -c -Wall dll.c
dllwrap dll.o --dllname=printy.dll -Wall

programma di prova

p.c
code:
#include <windows.h> int main(int argc, char *argv[]) { HINSTANCE dllHandle; void (*my_func)(char *str); dllHandle = LoadLibrary("printy.dll"); if(!dllHandle) { MessageBox(NULL, "Dll non caricata!", argv[0], MB_OK); return 0; } my_func = (void *) GetProcAddress(dllHandle, "printy"); if(my_func) my_func("Ciao :)"); else MessageBox(NULL, "Funzione non caricata!", argv[0], MB_OK); FreeLibrary(dllHandle); return 0; }

__________________
?

Last edited by yeah on 22-02-2005 at 21:58

22-02-2005 21:28
Click Here to See the Profile for yeah Click here to Send yeah a Private Message Find more posts by yeah Add yeah to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
cato
Wild boys always shine

User info:
Registered: Nov 2001
Posts: 5608 (0.65 al dì)
Location: lecco
Corso: F28
Anno: dottore
Time Online: 38 Days, 5:41:55 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

txs
domani lo provo

__________________

code:
  , ,  | | Me@Flickr  [ov0] | | my photo Blog  {| |} |@| Pallavolo La Nuova Rossa Milano --"-"--| | -------| | "If You Can't Open It, You Don't Own It"

22-02-2005 22:54
Click Here to See the Profile for cato Click Here to See the Blog of cato Click here to Send cato a Private Message Visit cato's homepage! Find more posts by cato Add cato to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
yeah
.grande:maestro.

User info:
Registered: Nov 2003
Posts: 1644 (0.21 al dì)
Location: Cologno Monzese
Corso: Informatica Magistrale
Anno: II
Time Online: 12 Days, 21:36:41 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Ora che riguardo il tuo codice, ho notato un problema:

code:
stringa[0]='a'; stringa[1]='b'; stringa[2]='a'; stringa[3]='c'; stringa[4]='o';

Non termini la stringa con un '\0'. Se il problema di memoria è una violazione di segmento (del tipo "la memoria non poteva essere (read)" o simile) con buona probabilità è colpa di quello :)

Per semplicità puoi sostituirlo con un strcpy(stringa, "abaco");

:)

__________________
?

22-02-2005 23:36
Click Here to See the Profile for yeah Click here to Send yeah a Private Message Find more posts by yeah Add yeah to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
cato
Wild boys always shine

User info:
Registered: Nov 2001
Posts: 5608 (0.65 al dì)
Location: lecco
Corso: F28
Anno: dottore
Time Online: 38 Days, 5:41:55 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

risolto: mancava un "cdecl" :P

code:
function hello(var stringa:array of integer):integer; cdecl; begin writeln('DLL:'); writeln(stringa[0]); writeln(stringa[1]); writeln(stringa[2]); writeln(stringa[3]); writeln(stringa[4]); result:=100; end;

__________________

code:
  , ,  | | Me@Flickr  [ov0] | | my photo Blog  {| |} |@| Pallavolo La Nuova Rossa Milano --"-"--| | -------| | "If You Can't Open It, You Don't Own It"

07-03-2005 17:11
Click Here to See the Profile for cato Click Here to See the Blog of cato Click here to Send cato a Private Message Visit cato's homepage! Find more posts by cato Add cato to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 22:52.    Post New Thread    Post A Reply
  Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.100 seconds (40.92% PHP - 59.08% MySQL) con 24 query.