Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Programming Talk / C++ / C# - vs 6.0 C++ dll command coding help

Author
Message
sovr
15
Years of Service
User Offline
Joined: 2nd Jan 2010
Location: USA
Posted: 6th Sep 2011 05:06
hello, I have been working on a code that would create a .dll file for dbpro (which would add commands to dbpro). I am currently using vs 6.0 c++ and I am having a problem with my code. I am trying to write text to a file using <fstream> but when I use ifstream file; (code bellow) it says that file and ifstream are undefined, can anyone help me? thanks in advance!

errors:


Compiling...
WRITEFILE.cpp
C:\Users\parker\AppData\Local\VirtualStore\Program Files (x86)\Microsoft Visual Studio\MyProjects\WRITEFILE\WRITEFILE.cpp(28) : error C2065: 'ifstream' : undeclared identifier
C:\Users\parker\AppData\Local\VirtualStore\Program Files (x86)\Microsoft Visual Studio\MyProjects\WRITEFILE\WRITEFILE.cpp(28) : error C2146: syntax error : missing ';' before identifier 'file'
C:\Users\parker\AppData\Local\VirtualStore\Program Files (x86)\Microsoft Visual Studio\MyProjects\WRITEFILE\WRITEFILE.cpp(28) : error C2065: 'file' : undeclared identifier
C:\Users\parker\AppData\Local\VirtualStore\Program Files (x86)\Microsoft Visual Studio\MyProjects\WRITEFILE\WRITEFILE.cpp(29) : error C2228: left of '.open' must have class/struct/union type
C:\Users\parker\AppData\Local\VirtualStore\Program Files (x86)\Microsoft Visual Studio\MyProjects\WRITEFILE\WRITEFILE.cpp(32) : error C2228: left of '.is_open' must have class/struct/union type
C:\Users\parker\AppData\Local\VirtualStore\Program Files (x86)\Microsoft Visual Studio\MyProjects\WRITEFILE\WRITEFILE.cpp(34) : error C2297: '<<' : illegal, right operand has type 'char [6]'
C:\Users\parker\AppData\Local\VirtualStore\Program Files (x86)\Microsoft Visual Studio\MyProjects\WRITEFILE\WRITEFILE.cpp(39) : error C2228: left of '.close' must have class/struct/union type
Error executing cl.exe.

WRITEFILE.dll - 7 error(s), 0 warning(s)






code:


// WRITEFILE.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <stdlib.h>


BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{

return true;

}

#define COMMAND _declspec ( dllexport )


COMMAND void PrintText( LPSTR pString )
{


ifstream file;
file.open("hello.txt");
if (pString)
{
if (file.is_open())
{
file << "hello";
}


}
file.close();

}
COMMAND int GetValue ( void )
{
return 42;
}

sov the game creator!
sovr
15
Years of Service
User Offline
Joined: 2nd Jan 2010
Location: USA
Posted: 6th Sep 2011 05:11
ok this code is from the tutorial that comes with the dbpro (thats why there is GET VALUE() class) just thought I would say that.

sov the game creator!
Robert The Robot
18
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 6th Sep 2011 10:51 Edited at: 6th Sep 2011 10:53
Hi, just been looking at your code, and it's not too hard to fix.

Your first error message is that "ifstream" is an undeclared identifier, even though you included the <fstream> header file. The reason is that ifstream isn't directly available from the header, as it's a member of the "std" namespace - a very extensive group of commands holding all of C++'s standard methods (everything from outputing text to screen to creating dynamic arrays and beyond). So, after your #include commands, put "using namespace std;"

Also, you've made a slight typo - you don't want "ifstream file", you want "ofstream file". Only one letter in it, but it affects what you can do with the file once it's opened. ifstream is for input, so you can read in data from the text file. You're trying to write a string to a file, so you want ofstream for output.

The corrected code is shown below (Oh, I've also indented it, just to make it more readable - always keep your code tidy, or it's hell trying to find a mistake in a nested loop):



Hope this helps!

We spend our lives chasing dreams. Dark Basic lets us catch some of them.
sovr
15
Years of Service
User Offline
Joined: 2nd Jan 2010
Location: USA
Posted: 6th Sep 2011 17:14
thank you for that code, it compiles... but one other thing does not work right. The Get Value() works fine but the Print Text("") command does not work :-(. It has to be with the string table, here this is what I have for that command (and the get value()) as captions:

IDS_STRING1 1 PRINT TEXT%S%?PrintText@@YAXPAD@Z%String
IDS_STRING2 2 GET VALUE[%L%?GetValue@@YAHXZ

again thank you very much!

sov the game creator!
sovr
15
Years of Service
User Offline
Joined: 2nd Jan 2010
Location: USA
Posted: 6th Sep 2011 17:16
whoops, not all of that is in the caption, just the last part (PRINT TEXT... and GET VALUE... are in the caption).

sov the game creator!
Robert The Robot
18
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 6th Sep 2011 19:28 Edited at: 6th Sep 2011 19:30
Hmm, I don't really see anything wrong with your string table entries - when you say it doesn't work, what exactly is happening?

You said
does not work, if you're actually calling what's in that code snippet then DBPro won't recognise it. Try calling
instead.

The difference is that "Print Text" does not return any value, and so it is a command (like DBP "Make Object Cube ObjID, size). "Get Value" returns a value, and so is an expression (denoted by the "[" symbol in the string table entry). It's like DBP's "Object Exist(ObjNum)".

I think what may have confused you is that in DBPro, all user-defined functions are called using parameters in brackets - with plugins, you're extending the DBP language so you follow a slightly different set of rules.

Hope this helps!

[edit] Just thought, if you can't find the output file "hello.txt", check your temp directory (or wherever DBP puts the compiled exe). The file should be there.

We spend our lives chasing dreams. Dark Basic lets us catch some of them.
sovr
15
Years of Service
User Offline
Joined: 2nd Jan 2010
Location: USA
Posted: 6th Sep 2011 20:43
I will try that out when I have a computer available and let you know how it goes. But what happens is the dbpro compiler does not recognize the command at all. Again get value() works fine, this morning I did try print text("hello") but still the same thing,
dbpro will not recognize it.

Ps it is funny because the compiler thinks it is the command print and text but even changing the command from
to
it will not recognize it.

Again thank you a ton!

sov the game creator!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 7th Sep 2011 00:29
No, it won't work, because you are telling it to call a function called 'Print text' when you have instead provided a command called 'Print text', just like Robert has told you.

Change 'Print text(string)' to 'Print text string' and it will work.

sovr
15
Years of Service
User Offline
Joined: 2nd Jan 2010
Location: USA
Posted: 7th Sep 2011 01:11
it works! thank you so much for your help!

sov the game creator!
sovr
15
Years of Service
User Offline
Joined: 2nd Jan 2010
Location: USA
Posted: 7th Sep 2011 05:39
there is one thing I forgot to ask, about the string table within resources (.rc file), if I were to change the code so that it would receive two strings (ex: print text "hello","goodbye") how would I change what I have in the string table (for that command) to make it so it will do two strings. I do know within the %S% to put another S inside, and on the end to add , String, but with the ?Print Text@@YAXPAD@Z I have no clue how to edit that part so it would work. Thank you!

sov the game creator!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 7th Sep 2011 15:22
You should do what the help file says to do and check in the DLL to see what has been exported - 'To find the decorated name of your function, simply load your DLL into NOTEPAD, and search for the function name, and you will find it.'

Or you could use the DUMPBIN utility on the DLL to see it spelt out a little more clearly (dumpbin -exports <your dll name>

Diggsey
19
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 7th Sep 2011 23:46
DLL Export Viewer makes it even easier. Just open your DLL with it and it will show you the decorated names (As long as you don't choose the "undecorate names" option)

[b]
sovr
15
Years of Service
User Offline
Joined: 2nd Jan 2010
Location: USA
Posted: 7th Sep 2011 23:56
wow, that is cool, thank you.

sov the game creator!

Login to post a reply

Server time is: 2025-05-19 10:38:31
Your offset time is: 2025-05-19 10:38:31