CÁC GIẢI PHÁP LẬP TRÌNH C# - Trang 597

597

Chương 15: Khả năng liên tác mã lệnh không-được-quản-lý

Console.ReadLine();

}

// GetErrorMessage trả về thông điệp lỗi

// tương ứng với mã lỗi errorCode.

public static string GetErrorMessage(int errorCode) {

int FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100;

int FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200;

int FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000;

int messageSize = 255;

string lpMsgBuf = "";

int dwFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER |

FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;

int retVal = FormatMessage(dwFlags, 0, errorCode, 0,

ref lpMsgBuf, messageSize, 0);

if (0 == retVal) {

return null;

} else {

return lpMsgBuf;

}

}

}

Sau đây là kết xuất của ứng dụng:

1400

Invalid window handle.

6.

6.

S d ng thành ph n COM trong .NET-client

ử ụ

S d ng thành ph n COM trong .NET-client

ử ụ

Bạn cần sử dụng thành phần COM trong một .NET-client.

Sử dụng một Primary Interop Assembly, nếu có. Nếu không, tạo một Runtime
Callable Wrapper
bằng Type Library Importer (Tlbimp.exe), hoặc tính năng Add
Reference
trong Visual Studio .NET.