» »

kako dll? /c++

kako dll? /c++

jlpktnst ::

Zanima me kako narediti *.dll knjižnico. So kakšne posebnosti pri definicijah, deklaraciji, kodi(ključne besede)... In kako to prevedeš(compajlaš).Kako jo lahko povežeš v program?
Dober bi bil tudi source *.cpp(*.c) in *.h fajlov za knjižnico in program,ki to uporablja.
LP

ender ::

zakaj rabiš DLL? in, koliko znaš programirat?
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.

d-mon ::

Upam, da ti tole pomaga.
Ce ti ne DLL ni zate. Ce uporabljas za svoje programe, se ponavadi DLL ne pise. Zapec vse v EXE.

Ce pa hoces modularno delat programe delaj s COM objekti. Ti vsaj ne bo treba EXE datotek zmeri prekompajlat, ko bos dll spremenu.



Header File (dlltest.h):

#ifndef _DLLTEST_H_
#define _DLLTEST_H_

#include
#include
#include

extern "C" __declspec(dllexport) void NumberList();
extern "C" __declspec(dllexport) void LetterList();


#endif





Source File (dlltest.cpp):

#include "dlltest.h"

#define MAXMODULE 50

char module[MAXMODULE];


extern "C" __declspec(dllexport)

void NumberList() {

GetModuleFileName(NULL, (LPTSTR)module, MAXMODULE);

cout << "\n\nThis function was called from "
<< module
<< endl << endl;

cout << "NumberList(): ";


for(int i=0; i<10; i++) {

cout << i << " ";
}

cout << endl << endl;
}



extern "C" __declspec(dllexport)

void LetterList() {

GetModuleFileName(NULL, (LPTSTR)module, MAXMODULE);

cout << "\n\nThis function was called from "
<< module
<< endl << endl;

cout << "LetterList(): ";


for(int i=0; i<26; i++) {

cout << char(97 + i) << " ";
}

cout << endl << endl;
}



DLL Test Source File (dllrun.cpp) - Win32 Console Application:
#include
#include
#include
#include

#define MAXMODULE 50

typedef void (WINAPI*cfunc)();

cfunc NumberList;
cfunc LetterList;

void main() {

HINSTANCE hLib=LoadLibrary("DLLTEST.DLL");


if(hLib==NULL) {

cout << "Unable to load library!" << endl;
getch();
return;
}

char mod[MAXMODULE];

GetModuleFileName((HMODULE)hLib, (LPTSTR)mod, MAXMODULE);
cout << "Library loaded: " << mod << endl;


NumberList=(cfunc)GetProcAddress((HMODULE)hLib, "NumberList");
LetterList=(cfunc)GetProcAddress((HMODULE)hLib, "LetterList");

if((NumberList==NULL) || (LetterList==NULL)) {

cout << "Unable to load function(s)." << endl;
FreeLibrary((HMODULE)hLib);
return;
}

NumberList();
LetterList();

FreeLibrary((HMODULE)hLib);

getch();
}



[D-mon]


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

Kodirni program ADFGX oz. ADFGVX

Oddelek: Programiranje
51040 (1000) Small_Hobit
»

c++ lib,dll,h za uporabo v C#

Oddelek: Programiranje
91953 (1752) noraguta
»

uporaba C++ unmanaged kode v C#.NET projektu

Oddelek: Programiranje
111899 (1622) krho
»

[c#] naloga za maturo...rabim majhno pomoc

Oddelek: Programiranje
192333 (1670) ql000
»

C in Dll

Oddelek: Programiranje
71126 (1033) Senitel

Več podobnih tem