Skip to main content
gamedev.net
🔒 Locked

Problems :(

Started by Drezard 1 reply 750+ views
Original Post
Drezard
Drezard
Hello This is my working (compiling DLL): Code: #include #include #include #include using namespace std; extern "C" __declspec(dllexport)void new_user(string username, string password , string charname); BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { return TRUE; } void new_user(string username, string password , string charname) { string filename = username + ".txt"; ofstream file( "haxor.txt" ); string output = username + " "; output = output + password; output = output + " "; output = output + charname; file<<output; file.close(); } Now the problem is that it doesnt generate the correct output. It doesnt create a Txt file. The function runs and does nothing. Whats wrong? (Wrong function?) - Cheers, Daniel
Evil Steve
Evil Steve
Do you ever call new_user()? Have you tried putting a MessageBox() in there so you know it's being called? Have you tried specifying a full path for the output file instead of a relative path (E.g. "C:\\hax0r.txt" instead of "hax0r.txt")?
Bregma
Bregma
I would suggest that writing code that checks for errors is more effective at finding problems at runtime than posting to online forums.

Every time you open a file you need to check to see if it succeeds.

Every time you write to a file, it could fail. You need to check to see if it succeeds.

You will find your file I/O library will even provide a way to retrieve information about failures in human-readable format.
#include <cerrno>#include <cstring>#include <fstream>#include <iostream>int main(){  std::ofstream file("haxor.txt");  if (!file)  {    std::cerr << "error " << errno << "opening file: " << std::strerror(errno) << "\n";    exit 1;  }}


--smw
Stephen M. Webb
Professional Free Software Developer

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.