Showing posts with label dll. Show all posts
Showing posts with label dll. Show all posts

2009/08/20

Watch DLL Function Names

1. Start -> All Programs -> Visual Studio 2005 -> Visual Studio Tools -> Visual Studio 2005 Command Prompt
2. type "dumpbin /exports [path\filenames.dll]"
!

2009/08/19

Dynamic Link Library (DLL)

From Wikipedia,

Dynamic-link library (also written without the hyphen), or DLL, is Microsoft's implementation of the shared library concept in the Microsoft Windows and OS/2 operating systems. These libraries usually have the file extension DLL, OCX (for libraries containing ActiveX controls), or DRV (for legacy system drivers). The file formats for DLLs are the same as for Windows EXE files — that is, Portable Executable (PE) for 32-bit and 64-bit Windows, and New Executable (NE) for 16-bit Windows. As with EXEs, DLLs can contain code, data, and resources, in any combination.

In the broader sense of the term, any data file with the same file format can be called a resource DLL. Examples of such DLLs include icon libraries, sometimes having the extension ICL, and font files, having the extensions FON and FOT.

!

2009/06/22

C# - Call C++ Function in DLL with Struct as Input Parameter

C++ DLL Code
#pragma pack
(push)
#pragma pack(1)
typedef struct EmmStruct {
int len;
} EMMSTRUCT, *LPEMMSTRUCT;

typedef struct MyStruct {
int iParam;
long size;
LPEMMSTRUCT lpEmmStructArr;
} MYSTRUCT, *LPMYSTRUCT;
#pragma pack(pop)

extern "C" void __declspec(dllexport) __stdcall TestFunction(LPMYSTRUCT lpMyStruct)
{
lpMyStruct->iParam = 100;
lpMyStruct->size = 10;
lpMyStruct->lpEmmStructArr = new EMMSTRUCT[lpMyStruct->size];
for(int i=0;isize;i++) {
lpMyStruct->lpEmmStructArr[i].len = i;
}
}


C# Codeusing System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace csharptest
{
[StructLayout(LayoutKind.Explicit)]
public struct EmmStruct
{
[FieldOffset(0)]
public int len;
}

[StructLayout(LayoutKind.Explicit)]
public struct MyStruct
{
[FieldOffset(0)]
public int iParam;
[FieldOffset(4)]
public int size;
[FieldOffset(8)]
public IntPtr ptrEmmStruct;
}

class Program
{

[DllImport("dllforcsharp.dll", CallingConvention=CallingConvention.Winapi)]
public extern static void TestFunction(IntPtr ptr);

static void Main(string[] args)
{
try
{
MyStruct s = new MyStruct();
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(s));
Marshal.StructureToPtr(s, ptr, false);

TestFunction(ptr);

s = (MyStruct)Marshal.PtrToStructure(ptr, typeof(MyStruct));

EmmStruct ret;
for (int i = 0; i < ptr2 =" new IntPtr(s.ptrEmmStruct.ToInt32() + 4 * i);
ret = (EmmStruct)Marshal.PtrToStructure(ptr2, typeof(EmmStruct));
}

Marshal.FreeHGlobal(ptr);
}
catch (Exception e)
{
string str = e.Message;
}
finally
{
}
}
}
}

Google Analytics

Blog Archive

Followers