C·¢Éù³ÌÐò
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <math.h>
#include <conio.h>
typedef struct {
short int pitch;
short int duration;
} NOTE;
NOTE notes[] = {{14, 500}, {16, 500}, {12, 500}, {0, 500}, {7, 1000}};
void setfreq(int hz)
{
hz = 1193180 / hz; // clocked at 1.19MHz
_outp(0x43, 0xb6); // timer 2, square wave
_outp(0x42, hz);
_outp(0x42, hz >> 8);
}
void playnote(NOTE note)
{
_outp(0x61, _inp(0x61) | 0x03); // start speaker going
setfreq((int)(400 * pow(2, note.pitch / 12.0)));
Sleep(note.duration);
_outp(0x61, _inp(0x61) & ~0x03); // stop that racket!
}
int main(int argc, char* argv[])
{
int i;
HANDLE h;
h = CreateFile("\\\\.\\giveio", GENERIC_READ, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(h == INVALID_HANDLE_VALUE)
{
printf("Couldn't access giveio device\n");
return -1;
}
for(i=0; i < sizeof(notes)/sizeof(int); ++i)
playnote(notes[i]);
CloseHandle(h);
return 0;
}
Óм¸µãÐèҪעÒ⣺
1£¬\\\\.\\giveioÊÇ´ò¿ªµÄÉ豸£¬ÓÉÓÚÊÇÓÃ\\תÒå±íʾ\£¬ËùÒÔÉÏÊöÆäʵÊDZíʾ\\ . \
2£¬ÕâÖֵײãµÄ±à³ÌºÜÉÙ¡£ÒÔÉÏ_outp·ÃÎʵÄÊǵײã¼Ä´æÆ÷£¬¹¦ÄÜÈç×¢
Ïà¹ØÎĵµ£º
extern "C" Ïê½â
ÔÚC++ÖУ¬ÎªÁËÖ§³ÖÖØÔØ»úÖÆ£¬ÔÚ±àÒëÉú³É»ã±à´úÂëʱ£¬º¯ÊýµÄÃû×ÖÒª¼ÓÈ뺯ÊýµÄ²ÎÊýÀàÐÍ»òÕß·µ»ØÖµÀàÐ͵ÈÐÅÏ¢
ÔÚCÖУ¬ÒòûÓÐÖØÔØ»úÖÆ£¬±àÒëºóµÄ´úÂëÖ»ÊǼòµ¥µÄº¯ÊýÃû×Ö¶øÒÑ£¬²»¼ÓÈëÆäËûµÄÐÅÏ¢
1. ²»¼ÓÈëextern "C"
testexternc.cpp
int mytest(void)
{
int a=10,b=20;
int c=a+b;
ret ......
CÊÇÃæÏò¹ý³ÌµÄ³ÌÐòÉè¼Æ£¬³ÌÐò=Êý¾Ý½á¹¹+Ëã·¨ [×îÔʼ£¬µ«±à¸ö³Ìȷʵ²»Ò×]
C++ÊÇÃæÏò¶ÔÏóµÄ³ÌÐòÉè¼Æ£¬³ÌÐò=¶à¸öÀà+ÏûÏ¢(Àà=Êý¾Ý½á+Ëã·¨)[±È½ÏÈÝÒ×ÉÏÊÖ]
C# ÊÇ´¿ÃæÏò¶ÔÏóµÄÓïÑÔ[¸ü¼Ó±È½ÏÈÝÒ×ÉÏÊÖ]
VC/VC++/VC# Ö»ÊÇÓÃÀ´¿ª·¢C/C++/C#Ó¦ÓóÌÐòµÄÈí¼þÖеÄÒ»ÖÖ¡£
......
²Ù×÷ϵͳµÄÒ»¸ö¾µäÎÊÌâÊÇ"Éú²úÕß-Ïû·ÑÕß"ÎÊÌâ, ÕâÉ漰ͬ²½ÐźÅÁ¿ºÍ»¥³âÐźÅÁ¿µÄÓ¦ÓÃ, ÔÚÕâÀï,ÎÒÓÃÏ̵߳Äͬ²½ºÍ»¥³âÀ´ÊµÏÖ.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <semaphore.h>
#define N 2 // Ïû·ÑÕß» ......
#include <stdio.h>
#define N 19
int main()
{
int i;
for (i=0;i<=N;i++)
{
printf("%*.*s%-*.*s\n",N,i<=N/2?i:N-1,"*******************",\
N,i<=N/2?i+1:N-i+1,"*******************");
}
return 0;
}
%m.ns ......
ÒªÁ˽âÖ¸Õë,¶à¶àÉÙÉÙ»á³öÏÖһЩ±È½Ï¸´ÔÓµÄÀàÐÍ,ËùÒÔÎÒÏȽéÉÜ
Ò»ÏÂÈçºÎÍêÈ«Àí½âÒ»¸ö¸´ÔÓÀàÐÍ,ÒªÀí½â¸´ÔÓÀàÐÍÆäʵºÜ¼òµ¥,Ò»
¸öÀàÐÍÀï»á³öÏֺܶàÔËËã·û,ËûÃÇÒ²ÏñÆÕͨµÄ±í´ïʽһÑù,ÓÐÓÅÏÈ
¼¶,ÆäÓÅÏȼ¶ºÍÔËËãÓÅÏȼ¶Ò»Ñù,ËùÒÔÎÒ×ܽáÁËÒ»ÏÂÆäÔÔò:
´Ó±äÁ¿Ãû´¦Æð,¸ù¾ÝÔËËã·ûÓÅÏȼ¶½áºÏ,Ò»²½Ò»²½·ÖÎö.
ÏÂÃæÈÃÎÒÃÇÏÈ´Ó¼òµ¥µÄÀàÐ ......