Hi all:

Trying to follow this tutorial http://www.codeproject.com/KB/COM/com_in_c1.aspx I'v got this code:

// MS VCpp console application

long SetString (char*); // function prototype
typedef long SetStringPtr(char*);
long GetString(char*, long); // function prototype
typedef long GetStringPtr(char*, long);

typedef struct {
SetStringPtr* SetString;
GetStringPtr* GetString;
} IExampleVtbl;

typedef struct {
IExampleVtbl* lpVtbl;
DWORD count;
char buffer[80];
} IExample;


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

IExample* example;
example = (IExample*)GlobalAlloc(GMEM_FIXED, sizeof(IExample));

// init members
example->count = 1;
example->buffer[0] = 0;
example->lpVtbl->SetString = SetString; // Throw exception!!
example->lpVtbl->GetString = GetString;

HGLOBAL hres = GlobalFree((HGLOBAL) example);
system ("PAUSE");
return EXIT_SUCCESS;
}

long SetString (char* str) { // definition
return (0);
}

long GetString(char* buffer, long length) { // definition
return(0);
}

At run-time there a an exception in the commented line.

There is some theoretical justification that can not be made the initialization of that function-pointer in that place?

Thanks in advance