脚本系统:c 内嵌python计算机二级考试

文章作者 100test 发表时间 2009:06:15 10:08:26
来源 100Test.Com百考试题网


  编辑特别推荐:

  全国计算机等级考试(等考)指定教材

  全国计算机等级考试学习视频

  全国计算机等级考试网上辅导招生

  全国计算机等级考试时间及科目预告

  百考试题教育全国计算机等级考试在线测试平台

  全国计算机等级考试资料下载

  全国计算机等级考试论坛

  计算机等级考试四级应用题解析汇总

  2009年下半年全国计算机二级考试报名时间从6月1日起已经开始报名。详情点击:2009年下半年全国计算机等级考试各地报名点汇总。2009年下半年全国计算机二级考试时间是2009年9月19日至23日。更多优质资料尽在百考试题论坛 百考试题在线题库

  // liquidx.cpp : Defines the entry point for the console application.
  //
  #include "stdafx.h"
  #include <.boost/python/def.hpp>.
  #include <.boost/python/module.hpp>.
  #include <.boost/python/args.hpp>.
  #include <.boost/python/class.hpp>.
  #include <.boost/python/str.hpp>.
  #include <.boost/python/dict.hpp>.
  #include <.iostream>.
  #include <.string>.
  #include <.list>.
  #include <.map>.
  using namespace std.
  PyObject * RepeatString (PyObject *pSelf, PyObject *pParams)
  {
  char *pstrString.
  int iRepCount.
  PyArg_ParseTuple(pParams, "si", &.pstrString, &.iRepCount).
  for (int i = 0. i <. iRepCount. i )printf("---%d\n", i).
  return PyInt_FromLong(iRepCount).
  }
  int _tmain(int argc, _TCHAR* argv[])
  {
  Py_Initialize().
  Py_IsInitialized().
  PyImport_AddModule("HostAPI").
  //create a function table
  PyMethodDef HostAPIFuncs [] =
  {
  {"RepeatString", RepeatString, METH_VARARGS, NULL},
  {NULL, NULL, NULL, NULL}
  }.
  //initial the module with the function table
  Py_InitModule("HostAPI", HostAPIFuncs).
  PyObject *pName = PyString_FromString("helloworld").
  PyObject * pModule = PyImport_Import(pName).
  PyObject *pstr= NULL, *pDict= NULL.
  //get the module dict
  pDict = PyModule_GetDict(pModule).
  pstr = PyDict_GetItemString(pDict, "PrintStuff").//get the function with the dict
  PyObject_CallObject ( pstr, NULL ). //call the function
  PyObject *pFunc = PyDict_GetItemString(pDict, "RepCount").
  int  as = PyInt_AS_LONG(pFunc).
  printf( "**************************%d", as ).
  //Py_XDECREF(pFunc).
  Py_XDECREF(pstr).
  //Py_XDECREF(pDict).
  Py_XDECREF(pModule).
  Py_XDECREF(pName).
  Py_Finalize(). // 清除
  getchar().
  return 0.
  }
  Helloworld.py 如下:
  import HostAPI
  def PrintStuff():
  global RepCount
  RepCount = HostAPI.RepeatString("String repetition", 4)

相关文章


计算机二级C 技巧:C 鼠标全局钩子实现代码计算机二级考试
C语言声明的优先级规则计算机二级考试
脚本系统:c 内嵌python计算机二级考试
log4cxxC 的日志库使用随记计算机二级考试
最简单的foreach实现(VC
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛