Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

PythonµÄC/C++À©Õ¹

  Python
µÄ
C/C++
À©Õ¹
                         
By phidoit@gmail.com
 
¿ÉÀ©Õ¹ÐÔÊÇ
Python
µÄÒ»´óÌØÉ«£¬Ò»·½Ã棬ÓÉÓÚ
Python
ÊǽâÊÍÖ´Ðеģ¬Õâµ¼ÖÂÔËÐÐËٶȻá±È±àÒëÐÍÓïÑÔÂý£¬Òò´Ë¿ÉÒÔͨ¹ýʹÓÃ
C/C++
ÖØдºËÐIJ¿·Ö´úÂëÒÔ½â¾öÐÔÄÜÉϵÄÆ¿¾±
(
³ÌÐò
90%
µÄʱ¼äÔÙÔËÐÐ
10%
µÄ´úÂë
)
£»ÁíÒ»·½Ã棬¿ÉÒÔͨ¹ýÀ©Õ¹£¬´ïµ½Ìí¼ÓÕûºÏһЩ¶îÍâµÄ¹¦ÄÜÒÔ¼°±£³ÖרÓÐÔ´´úÂëµÄÄ¿µÄ¡£ÔÚ±¾ÎĽÓÏÂÀ´µÄ²¿·ÖÖÐÎÒÃǽ«ÌÖÂÛÈçºÎ±àд
C/C++
À©Õ¹´úÂ룬²¢Ê¹ÓÃËüÃǵŦÄÜ¡£
ÎÒÃÇÒª½¨Á¢µÄÊÇÒ»¸ö¿ÉÒÔÔÚ
Python
ÄÚÔËÐеÄ
C/C++
Ä£¿é£¬Òò´ËÐèÒª½â¾öÈçºÎʹ
C
´úÂëºÍ
Python
´úÂëÄܹ»½øÐн»»¥ÒÔ¼°Êý¾Ý¹²Ïí¡£À©Õ¹ÊÇͨ¹ýΪ
C
´úÂë±àд°ü×°º¯Êý
(
ÀàËÆÊÊÅäÆ÷
)
ʵÏÖË«Ïò½»»¥ºÍÊý¾Ý¹²ÏíµÄ¡£
 
Ò»£®Ò»°ãµÄ°üװģʽ
 
ÿһ¸ö°ü×°º¯ÊýÖ÷Òª×öÈý¼þÊ£º
1.
°ÑÊäÈëµÄ
Python
¶ÔÏóת»»Îª
C/C++
¶ÔÏó£»
2.
µ÷ÓÃ
C/C++
º¯Êý£»
3.
ת»»
C/C++
º¯Êý´¦ÀíµÄÊä³ö½á¹ûΪ
Python
¶ÔÏ󣬲¢·µ»Ø£»
 
ÏÈÓÃÒ»¸ö¼òµ¥ÑùÀýÃèÊöÄ£¿é´óÌåµÄ¹ý³Ì£º
 //wrap.cpp
//1.C´úÂë
#include "Python.h"
int add(int arg1, int arg2)
{
return arg1 + arg2;
}
//2.addµÄ°ü×°º¯Êý£º
static PyObject* wrap_add(PyObject *self, PyObject *args)
{
//°ÑÊäÈëµÄPython¶ÔÏóת»»ÎªC/C++ÄÜʶ±ðµÄÊý¾Ý
int arg1, arg2;
if(!PyArg_ParseTuple(args, "ii", &arg1, &arg2))
return NULL;
//µ÷ÓÃC/C++º¯Êý£¬µÃµ½½á¹û
int result = add(arg1,arg2);
//°ÑµÃµ½µÄ½á¹û°ü×°³ÉPython¶ÔÏ󣬲¢·µ»Ø
return (PyObject*)Py_BuildValue("i", result);
}
//3.Ϊģ¿éÌí¼ÓPyMethodDef·½·¨Êý×é
static PyMethodDef wrap_methods[] ={
{"add", wrap_add, METH_VARARGS},
{NULL, NULL}
};
//4.Ôö¼ÓÄ£¿é³õʼ»¯º¯ÊýInitModule
PyMODINIT_FUNC initwrap (void)
{
Py_InitModule("wrap ", wrap_methods);
}

    °ÑÉÏÃæµÄ´úÂë±àÒ룬Éú³É
wrap.pyd
¡£
    
 
Visual Studio 2005
±àÒë·½·¨²Î¿¼£º
http://blog.csdn.net/solo_lxy/archive/2007/07/20/1700515.aspx
&


Ïà¹ØÎĵµ£º

Microsoft Visual C++

 ¡¡¡¡²»ÖªµÀÔõôͻȻ¶ÔVC±à³Ì¸ÐÐËȤ£¬ÆäʵÎÒ¶¼²»ÖªµÀVCÊǸö¹þ£¬¾ÍÖªµÀÊdz̾ÍÏñÎÒÏÖÔÚѧµÄ×î¼òµ¥µÄPHP²î²»¶à°É£¬ÔÚPHPÉÏÔÛÒ²ÊǸö²Ë£¬»¹Ã»Ñ§ºÃ¾ÍÏëѧVC£¬ÎÒÕæÊǺÏ×ÔÒÑûÕÛ£¬»°²»¶à»°ÒÔÏÂÄÚÈÝÎÒÊǴӹȸèÀïËѵģ¬°Ù¶ÈÀïÓеģ¬²»ÊÇÎÒдµÄ¶«¶«£¬Ö»ÊÇ¿´ÁËÒ»¹þÔÚÕÒ¸öBLOG£¬×ªÒ»ÏÂÏÂ~
Ò»¡¢VCÊÇʲô£¿Ñ§VCÊÇѧʲô£¿
¡¡¡¡Ê×ÏÈV ......

C Sharp ÈëÃÅ£¨Ò»£©¿ØÖÆ̨

 C#ºÍVBScript£¬ActionScript£¬C++·Ç³£ÏàËÆ£¡
ÏÈÔÚCSÖн¨Á¢Ò»¸ö¿ØÖÆ̨³ÌÐò£¬ÔÙ´ò¿ª“Program.cs”¡£
ÔÚ void_Main ÊäÈëÒÔÏ´úÂ룺
 
            //ÕâÊÇ×¢ÊÍ£¬×¢ÊͽöÔÚµ÷ÊÔʱÓÐÓÃ
         ......

C´úÂëÓïÑÔתVB´úÂëµÄÎÊÌ⣺

Ë­ÄÜ°ïÎÒ°ÑÕâ¶Î´úÂëת³ÉVbµÄ´úÂ룬²»Ê¤¸Ð¼¤£¬Ð»Ð»£¡
void CTempDlg::OnOK()
{
  UpdateData(1);
  int nlen=m_edit1.GetLength();
  char *username=m_edit1.GetBuffer(nlen);//¶¨ÒåÒ»¸öÐÂ×Ö·û´®username,³¤¶ÈΪnlen£¬²¢½«m_edit1ÖеÄ×Ö·û´®Ò»¸ö¸ö·ÅÈëµ½usernameÊý×éÖÐ
  char strA[]="90123456 ......

VC++³ÌÐòÔ±Ó¦µ±ÈçºÎÔĶÁADOÎĵµ

VC++³ÌÐòÔ±Ó¦µ±ÈçºÎÔĶÁADOÎĵµ
¡¶ADO API²Î¿¼¡·ÓÃVBµÄÓï·¨ÃèÊöÁËADO APIµÄÄÚÈÝ¡£µ«ADO³ÌÐòԱȴʹÓÃ×Ų»Í¬µÄ±à³ÌÓïÑÔ£¬±ÈÈçVB,VC++£¬VJ++¡£¶Ô´Ë¡¶ADO for VC++µÄÓï·¨Ë÷Òý¡·ÌṩÁË·ûºÏVC++Óï·¨¹æ·¶µÄÏêϸÃèÊö£¬°üÀ¨¹¦ÄÜ¡¢²ÎÊý¡¢Òì³£´¦ÀíµÈµÈ¡£
ADO»ùÓÚÈô¸ÉµÄCOM½è¿ÚʵÏÖ£¬Òò´ËËüµÄʹÓöÔÓÚÒ»¸öÕý½øÐÐCOM±à³ÌµÄ³ÌÐòÔ±¶øÑÔ¸ü ......

PythonÖеÄFunction

     PythonÖУ¬º¯ÊýÊǿɱ»ÖØÓõijÌÐò¶Î¡£¶ÔÓÚº¯ÊýµÄ¶¨Ò壬¿ÉÒÔʹÓÃdef¹Ø¼ü×Ö¡£ÏÂÃæ¾ÍÏȶ¨ÒåÒ»¸öº¯Êý£º
      def foo():
print('function')
foo()
     ÔÚÉÏÊö´úÂëÖУ¬¶¨ÒåÁËÒ»¸öÃûΪfooµÄº¯Êý£¬Õâ¸öº¯ÊýûÓвÎÊý¡£×îºóÒ»ÐдúÂëµÄ¹¦ÄÜÊǵ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ