让C++动态执行某个文件中的部分C++代码,实现动态代码程序,该怎么处理

让C++动态执行某个文件中的部分C++代码,实现动态代码程序
我在做一个ISAPI时,遇到了这样的问题.
想把C++程序,先写到每个CPP文件中,然后由一个C++写的ISAPI根据不同的外部参数,调用对应的CPP文件,并把CPP文件的代码执行.
在网上查了一些关于C++的EVAL的文章,都是做简单的数学运算或者正则,但我的CPP中包含了复杂的C++代码,不知道如何解决.

还请各位高人指点.

------解决方案--------------------
C++的代码都是编译成可执行文件,然后执行的。你的程序需要先编译成可执行程序,然后执行的时候动态选择代码,再进行编译,生成可执行

文件,然后执行,相当于程序能够自动的判断源代码然后自己编译运行,很有难度啊...
------解决方案--------------------
1.用脚本语言,COM中有支持脚本的...
2.自己写解释器这个比较恼火的说

These files contain all of the code listings in

The Art of C++

The source code is organized into files by chapter.
Within each chapter file, the listings are stored
in the same order as they appear in the book.
Simply edit the appropriate file to extract the
listing in which you are interested.

C/C++ code

#include <iostream> 
#include <cstring> 
#include <cstdlib> 
#include <cctype> 
#include "mccommon.h" 
 
using namespace std; 
 
// Keyword lookup table. 
// Keywords must be entered lowercase. 
struct commands { 
  char command[20]; 
  token_ireps tok; 
} com_table[] = { 
  "if", IF,  
  "else", ELSE, 
  "for", FOR, 
  "do", DO, 
  "while", WHILE, 
  "char", CHAR, 
  "int", INT, 
  "return", RETURN, 
  "switch", SWITCH, 
  "break", BREAK, 
  "case", CASE, 
  "cout", COUT, 
  "cin", CIN, 
  "", END  // mark end of table 
}; 
 
// This structure links a library function name 
// with a pointer to that function. 
struct intern_func_type { 
  char *f_name; // function name 
  int (*p)();   // pointer to the function 
} intern_func[] = { 
  "getchar", call_getchar, 
  "putchar", call_putchar, 
  "abs", call_abs, 
  "rand", call_rand, 
  "", 0  // null terminate the list 
}; 
 
// Entry point into parser. 
void eval_exp(int &value) 
{ 
  get_token(); 
 
  if(!*token) { 
    throw InterpExc(NO_EXP); 
  } 
 
  if(*token == ';') { 
    value = 0; // empty expression 
    return; 
  } 
 
  eval_exp0(value); 
 
  putback(); // return last token read to input stream 
}

------解决方案--------------------
我个人觉得,要实现一个这样的程序,必须要在内部实现一个编译器才行!因为这个程序release出去以后,不能保证用户的机器上一定有编

译器,所以必须自身携带编译器。而编译器可以是第一次编译的时候生成的可执行文件里面就附带了。然后release出去以后,在所有的机器

上都能正常的check源码文件,并且和自己的代码揉合,形成一套新的代码,然后调用自身的编译器来进行第二次编译,这个程序就是最终结

果了...

以上只是一个个人考虑的流程,仅供参考!
------解决方案--------------------
The Art of C++

搜索一下,里面最后一章讲了一个简单的C++解释器的实现
------解决方案--------------------
C/C++ code
 

//MSDN上内嵌vbs的例子(部分代码)
//建议使用这种方法
//写解释器难度相对较高,成本也大
// Your IActiveScriptSite implementation...
class MyActiveScriptSite : public IActiveScriptSite {
private:
ULONG m_dwRef; // Reference count
public:
IUnknown *m_pUnkScriptObject; // Pointer to your object that is exposed
// to the script engine in GetItemInfo().

MyActiveScriptSite::MyActiveScriptSite() {m_dwRef = 1;}
MyActiveScriptSite::~MyActiveScriptSite() {}

// IUnknown methods...
virtual HRESULT _stdcall QueryInterface(REFIID riid, void **ppvObject) {
*ppvObject = NULL;
return E_NOTIMPL;
}
virtual ULONG _stdcall AddRef(void) {
return ++m_dwRef;
}
virtual ULONG _stdcall Release(void) {
if(--m_dwRef == 0) return 0;
return m_dwRef;
}

// IActiveScriptSite methods...
virtual HRESULT _stdcall GetLCID(LCID *plcid) {