I currently encounter three categories of.dll files that represent completely different meanings.
One is under c++. Inside the.dll file is equivalent to machine code, called dynamic link library, which is connected by static and dynamic connections.
The following is a static connection
//Used for static connections
#include "stdafx.h"
//The key is to add this sentence, meaning to export programs in C to DLL s
extern "C"_declspec(dllexport) void maopao(int *p,int count);
void maopao(int *p,int count)
{
int temp=0;
for(int i=1;i<count;i++)
{
for(int j=count-1;j>=i;j--)
{
if(p[j]>p[j-1])
{
temp=p[j];
p[j]=p[j-1];
p[j-1]=temp;
}
}
}
}
//call
#include<iostream>
#include<time.h>
using namespace std;
//Change export to import to export variable import
extern "C"_declspec(dllimport) void maopao(int *p,int count);
int main()
{
int a[10];
srand(time(0));
for(int i=0;i<10;i++)
a[i]=rand()%50;
maopao(a,10);
for(int i=0;i<10;i++)
cout<<a[i]<<endl;
getchar();//For debugging convenience
return 0;
}
Here's a dynamic connection, the same everywhere
#include "stdafx.h"
//The key is to add this sentence, meaning to export programs in C to DLL s
extern "C"_declspec(dllexport) void maopao(int *p,int count);
void maopao(int *p,int count)
{
int temp=0;
for(int i=1;i<count;i++)
{
for(int j=count-1;j>=i;j--)
{
if(p[j]>p[j-1])
{
temp=p[j];
p[j]=p[j-1];
p[j-1]=temp;
}
}
}
}
#include<iostream>
#include<Windows.h>
#include<time.h>
typedef int(*Dllfun)(int *,int);
using namespace std;
int main()
{
Dllfun maopao1;
HINSTANCE hdll;
hdll=LoadLibrary("D:\\net Source code\\maopaoa_dll\\Debug\\maopaoa_dll.dll");
if(hdll==NULL)
{FreeLibrary(hdll);
}
maopao1=(Dllfun)GetProcAddress(hdll,"maopao");
if(maopao1==NULL)
{FreeLibrary(hdll);
}
int a[10];
srand(time(0));
for(int i=0;i<10;i++)
a[i]=rand()%50;
maopao1(a,10);
for(int i=0;i<10;i++)
cout<<a[i]<<endl;
FreeLibrary(hdll);
}
The second is.dll, which is an AXtivex control. It is a kind of encapsulation of Microsoft's common controls, such as charts and spectrum control. It is often used in c++ and is also a binary file.
Connection #connect ('...')
The third is in c#, called an assembly, which runs on the.net framework and does not contain machine code itself and needs to be converted from the.net framework to machine code.There are two main ways to invoke it.One is an assembly reference, which is managed in the vs project, and the other is through reflection, which reflects the code as follows
Assembly asm= Assembly.LoadFile("Route..");
foreach (var type in asm.GetTypes())
{
//If it isISayInterface
if (type.GetInterfaces().Contains(typeof (ISay)))
{
//Create an interface type instance
var isay = Activator.CreateInstance(type) as ISay;
if (isay != null)
{
result.Add(isay);
}
}
}