| | |
Problem with DLL i'm coding for a game
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Sep 2008
Posts: 3
Reputation:
Solved Threads: 0
Hello,
Usually I can find solutions to problems that seem to arise when I'm coding for this game, but I'm stumped on why this is happening..
So I found out how to get the text from the last line of the text box on this game, and I want to separate the player name and what they said and store them in different char arrays.
So I made multiple variances of what I think would work, but they all seem to make the same thing happen; they make the last thing that was said disappear! I'm thinking that I'm misunderstanding something so I'm hoping one of you guys could help me out on this.
Here is the source code:
Oh, and here's pictures on before and after what it looks like:
http://i37.tinypic.com/11lr3hw.jpg
http://i38.tinypic.com/rc91qw.jpg
Is it a problem with pointers or something? I'm soo confused
Usually I can find solutions to problems that seem to arise when I'm coding for this game, but I'm stumped on why this is happening..
So I found out how to get the text from the last line of the text box on this game, and I want to separate the player name and what they said and store them in different char arrays.
So I made multiple variances of what I think would work, but they all seem to make the same thing happen; they make the last thing that was said disappear! I'm thinking that I'm misunderstanding something so I'm hoping one of you guys could help me out on this.
Here is the source code:
C++ Syntax (Toggle Plain Text)
struct PlayerAnswer{ const char* Player; const char* Answer; }; int GetLineCount() { DWORD* StageTextClassP = (DWORD*)StageTextClass; int theLineCount = 0; __asm{ mov ecx, StageTextClassP; mov eax, 0x004015F0; call eax; mov theLineCount, eax; } return theLineCount; } char* GetLastText() { DWORD* StageTextClassP = (DWORD*)StageTextClass; char* textLineText; int lineCount = GetLineCount()-2; textLineText = (char*)malloc(255); __asm{ mov ecx, StageTextClassP; mov eax, 0x0056EC10; push lineCount; call eax; mov textLineText, eax; } return textLineText; } PlayerAnswer GetLastPlayerAnswer() { PlayerAnswer pAnswer; if(string(GetLastText()).find(':') != string::npos) { char* plName = strtok(GetLastText(), ":"); char* plAnswer = strtok(NULL, "\0"); pAnswer.Player=plName; pAnswer.Answer=plAnswer; return pAnswer; } pAnswer.Answer="a"; pAnswer.Player="a"; return pAnswer; }
http://i37.tinypic.com/11lr3hw.jpg
http://i38.tinypic.com/rc91qw.jpg
Is it a problem with pointers or something? I'm soo confused
Last edited by Tishiablo; Sep 4th, 2008 at 5:33 pm. Reason: added code tags
•
•
Join Date: Jan 2008
Posts: 3,813
Reputation:
Solved Threads: 501
Looks like you have some Assembly code mixed in with the
I rewrote your
I think your best step is to really narrow down where exactly the problem is. Put some debugging statements in after the call to the
GetLineCount () and GetLastText () functions. I have no idea whether those functions are correct or not. In addition, I'm not familiar enough with Windows functions and DWORD, plus I have to relearn malloc every time I use it, which isn't often, so again, I can't comment on those two functions except to say that if there is not a good reason to use C and Assembly code, I would go with C++ code and use C++-strings rather than C-strings and use new rather than malloc .I rewrote your
GetText () function so I could use and try out the GetLastPlayerAnswer() function and as far as I can tell, it seems to work, at least if I understand correctly what it's supposed to do. Here is the program I tested: C++ Syntax (Toggle Plain Text)
#include <string> #include <iostream> #include <cstring> using namespace std; struct PlayerAnswer { const char* Player; const char* Answer; }; char* GetLastText() { char* someText = new char[8]; strcpy (someText, "Bob:Yes"); return someText; } PlayerAnswer GetLastPlayerAnswer() { PlayerAnswer pAnswer; if(string(GetLastText()).find(':') != string::npos) { char* plName = strtok(GetLastText(), ":"); char* plAnswer = strtok(NULL, "\0"); pAnswer.Player=plName; pAnswer.Answer=plAnswer; return pAnswer; } pAnswer.Answer="a"; pAnswer.Player="a"; return pAnswer; } int main () { PlayerAnswer pa = GetLastPlayerAnswer (); cout << "player = " << pa.Player << endl; cout << "answer = " << pa.Answer << endl; return 0; }
I think your best step is to really narrow down where exactly the problem is. Put some debugging statements in after the call to the
GetLastText () function and make sure it is returning what you want it to. If not, put some debugging code in to make sure that the GetLineCount () function does what it is supposed to do. Once you narrow down the exact function where the problem is located, go from there. Like I said, your GetLastPlayerAnswer () function appears to work to me, or at least it did with my example. •
•
Join Date: Jan 2008
Posts: 3,813
Reputation:
Solved Threads: 501
•
•
•
•
ha silly meI forgot to point out that everything did work fine until i had made GetLastPlayerAnswer. Could it be because I'm directly working off of the char* returned? if so, how would I fix that?
Run the program I posted and see if that function works correctly. It should split the string "Bob:Yes" into "Bob" and "Yes" and put it into a PlayerName variable, which I thought was the goal. Does it do that for you? Is that what you are looking for? If "Bob:Yes" works and some other string doesn't, list that string that doesn't work.
•
•
Join Date: Sep 2008
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
Run the program I posted and see if that function works correctly. It should split the string "Bob:Yes" into "Bob" and "Yes" and put it into a PlayerName variable, which I thought was the goal. Does it do that for you? Is that what you are looking for? If "Bob:Yes" works and some other string doesn't, list that string that doesn't work.
http://i37.tinypic.com/11lr3hw.jpg
http://i38.tinypic.com/rc91qw.jpg
You see how the text after the char name is removed? I want it to stay there.
•
•
Join Date: Jan 2008
Posts: 3,813
Reputation:
Solved Threads: 501
•
•
•
•
Yes that's what it was supposed to do, but the problem I was having was this:
http://i37.tinypic.com/11lr3hw.jpg
http://i38.tinypic.com/rc91qw.jpg
You see how the text after the char name is removed? I want it to stay there.
Well, then my guess is that your problem is elsewhere, in code that you haven't posted. Note that this function:
C++ Syntax (Toggle Plain Text)
PlayerAnswer GetLastPlayerAnswer() { PlayerAnswer pAnswer; if(string(GetLastText()).find(':') != string::npos) { char* plName = strtok(GetLastText(), ":"); char* plAnswer = strtok(NULL, "\0"); pAnswer.Player=plName; pAnswer.Answer=plAnswer; return pAnswer; } pAnswer.Answer="a"; pAnswer.Player="a"; return pAnswer; }
doesn't display anything anywhere; it merely splits the string in two. So somewhere after the call to this function, if you want to actually display the two broken strings, you have to do so by appending it to the text box or however you do it. But it appears that GetLastPlayerAnswer () is not intended to display anything. It merely breaks the string in two and it appears to be working. If it's also supposed to append the text to the text box, you'll have to add that part.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Problems with reading from a sequential file
- Next Thread: creat file for data in output folder
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






I forgot to point out that everything did work fine until i had made GetLastPlayerAnswer. Could it be because I'm directly working off of the char* returned? if so, how would I fix that? 