fireup6 0 Newbie Poster

I'm coding a dll which i am injecting into a target process. This dll patches some code to intercept some function calls before they happen, and i need to read whats in the registers and possibly modify them before i return.

The EDX register for instance, will hold an address pointing to the first char of a string.

Here is my current code to read the string:

#include "stdafx.h"
#include <Windows.h>
#include <string>

unsigned long _edx;
char textarray[5]; //create array to store 5 chars of the string

void Main()
{
	_asm{mov [_edx], edx} //save the value of EDX into an unsigned long
	char *pedx = reinterpret_cast<char*>(_edx);//create a pointer from the saved value
	for(int i = 0;i < 5; i++) {textarray[i] = *(pedx++);}//loop through 5 chars of the string and save them into our array
	string text(textarray,5);//save our array into a string
}

This code works, but I'm wondering if there are any more efficient and less troublesome ways of doing this. I've tried using GetThreadContext() which also works, but yields practically the same result with many more steps.

Thanks!