linux的api函数哪里有,C和C++怎么调用API

linux的api函数哪里有,C和C++怎么调用API,第1张

API是应用程序接口, 所以在应用级

直接与硬件打交道的是WINDOWS DDK, 设备驱动开发包,

这个开发包处理硬件

欲了解更详细的细节, 请参考CSDN:

比如:http://devcsdnnet/article/80266shtm

VxD API过程

一个VxD提供V86模式和保护模式API过程以允许在一个虚拟机中运行的应用程序和其它软件访问该VxD的特征。如果要使这些可选的过程有效,VxD必须将它们定义为Declare_Virtual_Device宏的参数,如果没有定义,VMM认为该VxD没有API过程。

在一个虚拟机中运行的应用程序或者其它软件通过设置BX寄存器为VxD标识并调用获取设备入口地址功能(INT 2FH 1684H功能)获取特定的虚拟机的API过程的入口地址,VMM返回该地址使得应用程序可以间接调用该API过程。

当一个应用程序调用该入口地址时,VMM保存该应用程序的寄存器并调用VxD相应的API过程,保存当前虚拟机的句柄到BX寄存器中并保存Client_Reg_Struc结构地址到EBP寄存器中。API过程必须检测客户寄存器的值(使用Client_Reg_Struc结构)以判断运行的API调用。

按照常规,大多数API过程使用AH寄存器指定主功能号,使用AL寄存器指定次功能号,其它客户寄存器用于附加参数。API过程通过修改客户寄存器返回值,API过程可以修改EAX、EBX、ECX、EDX、ESI和EDI寄存器。

下面的实例给出了一个实例API过程——VSAMPLED_API_Get_Version:

BeginProc VSAMPLED_API_Get_Version

movzx eax, [ebpClient_AX] ;取功能号

or eax, eax

jnz Undefined

Get_Version:

mov [ebpClient_AX], 030AH ;在客户寄存器AX中返回值

and [ebpClient_Flags], NOT CF_Mask ;清除进位标志

ret

Undefined:

or [ebpClient_Flags], CF_Mask ;设置进位标志

ret

EndProc VSAMPLED_API_Get_Version

照我说的做: 点菜单中的project->settings 来设定你这个工程的属性。 在打开的属性页中点击Link选项卡。 Category选项选择General(这个就是默认的) 下面第二个栏(Object/library modules)里写下你需要的lib库,多个库以空格分隔 例如: kernel32lib user32lib gdi32lib winspoollib comdlg32lib advapi32lib shell32lib ole32lib oleaut32lib uuidlib odbc32lib odbccp32lib msimg32lib winmmlib 注意:这个方法添加以后,如果你切换了左侧debug/release的选项。还需要重新添加一下才可以。 此外楼上兄弟的方法比较简便,不仅只在VC中适用。 h的文件就直接include 就行。

API都是C写的, 反过来也成,

你使用VC来做C程序, 可以直接用API

例子:

// DDcpp : Defines the entry point for the application

//

#include "stdafxh"

#include "resourceh"

#define MAX_LOADSTRING 100

// Global Variables:

HINSTANCE hInst; // current instance

TCHAR szTitle[MAX_LOADSTRING]; // The title bar text

TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text

// Foward declarations of functions included in this code module:

ATOM MyRegisterClass(HINSTANCE hInstance);

BOOL InitInstance(HINSTANCE, int);

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpCmdLine,

int nCmdShow)

{

// TODO: Place code here

MSG msg;

HACCEL hAccelTable;

// Initialize global strings

LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);

LoadString(hInstance, IDC_DD, szWindowClass, MAX_LOADSTRING);

MyRegisterClass(hInstance);

// Perform application initialization:

if (!InitInstance (hInstance, nCmdShow))

{

return FALSE;

}

hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_DD);

// Main message loop:

while (GetMessage(&msg, NULL, 0, 0))

{

if (!TranslateAccelerator(msghwnd, hAccelTable, &msg))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

}

return msgwParam;

}

//

// FUNCTION: MyRegisterClass()

//

// PURPOSE: Registers the window class

//

// COMMENTS:

//

// This function and its usage is only necessary if you want this code

// to be compatible with Win32 systems prior to the 'RegisterClassEx'

// function that was added to Windows 95 It is important to call this function

// so that the application will get 'well formed' small icons associated

// with it

//

ATOM MyRegisterClass(HINSTANCE hInstance)

{

WNDCLASSEX wcex;

wcexcbSize = sizeof(WNDCLASSEX);

wcexstyle = CS_HREDRAW | CS_VREDRAW;

wcexlpfnWndProc = (WNDPROC)WndProc;

wcexcbClsExtra = 0;

wcexcbWndExtra = 0;

wcexhInstance = hInstance;

wcexhIcon = LoadIcon(hInstance, (LPCTSTR)IDI_DD);

wcexhCursor = LoadCursor(NULL, IDC_ARROW);

wcexhbrBackground = (HBRUSH)(COLOR_WINDOW+1);

wcexlpszMenuName = (LPCSTR)IDC_DD;

wcexlpszClassName = szWindowClass;

wcexhIconSm = LoadIcon(wcexhInstance, (LPCTSTR)IDI_SMALL);

return RegisterClassEx(&wcex);

}

//

// FUNCTION: InitInstance(HANDLE, int)

//

// PURPOSE: Saves instance handle and creates main window

//

// COMMENTS:

//

// In this function, we save the instance handle in a global variable and

// create and display the main program window

//

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)

{

HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,

CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)

{

return FALSE;

}

ShowWindow(hWnd, nCmdShow);

UpdateWindow(hWnd);

return TRUE;

}

//

// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)

//

// PURPOSE: Processes messages for the main window

//

// WM_COMMAND - process the application menu

// WM_PAINT - Paint the main window

// WM_DESTROY - post a quit message and return

//

//

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

{

int wmId, wmEvent;

PAINTSTRUCT ps;

HDC hdc;

TCHAR szHello[MAX_LOADSTRING];

LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);

switch (message)

{

case WM_COMMAND:

wmId = LOWORD(wParam);

wmEvent = HIWORD(wParam);

// Parse the menu selections:

switch (wmId)

{

case IDM_ABOUT:

DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);

break;

case IDM_EXIT:

DestroyWindow(hWnd);

break;

default:

return DefWindowProc(hWnd, message, wParam, lParam);

}

break;

case WM_PAINT:

hdc = BeginPaint(hWnd, &ps);

// TODO: Add any drawing code here

RECT rt;

GetClientRect(hWnd, &rt);

DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);

EndPaint(hWnd, &ps);

break;

case WM_DESTROY:

PostQuitMessage(0);

break;

default:

return DefWindowProc(hWnd, message, wParam, lParam);

}

return 0;

}

// Mesage handler for about box

LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)

{

switch (message)

{

case WM_INITDIALOG:

return TRUE;

case WM_COMMAND:

if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)

{

EndDialog(hDlg, LOWORD(wParam));

return TRUE;

}

break;

}

return FALSE;

}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/12177576.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存