Severe embedding problems - please HELP!!!

Rodrigo B. de Oliveira rodrigobamboo at hotmail.com
Wed Nov 27 00:05:42 EST 2002


The problem with PyRun_File might be related to the fact that the FILE
structure differs from release to debug builds (or your program might
be statically linking to the CRT)...

Anyways, the following works for me:

<snip language="C++">
#include "stdafx.h"

char* read(const char* filename)
{
	char* buffer = 0;
	FILE* file = fopen(filename, "r");
	fseek(file, 0, SEEK_END);
	size_t size = ftell(file);
	if (size)
	{
		buffer = (char*)malloc(size + 1);
		fseek(file, 0, SEEK_SET);
		size = fread(buffer, sizeof(char), size, file);
		buffer[size] = 0;
	}
	fclose(file);
	return buffer;
}


int _tmain(int argc, _TCHAR* argv[])
{
	Py_Initialize();

	char* src = read("hello.py");
	PyRun_SimpleString(src);
	free(src);

	Py_Finalize();
	return 0;
}
</snip>

Rodrigo



More information about the Python-list mailing list