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.

Dark GDK / dbOpenToWrite() *always* fails

Author
Message
wtfsven
13
Years of Service
User Offline
Joined: 1st Oct 2011
Location:
Posted: 8th Oct 2011 01:12 Edited at: 8th Oct 2011 13:36
I'm trying to store some numbers in a file, but I'm having a strange problem: dbOpenToWrite() literally NEVER opens the file. Even something like this...

9: //...
10: dbOpenToWrite(1,"data.dat");
11: if (!dbFileOpen(1)) dbPrint("Failed");
12: //...

...will print "Failed" to the screen. What gives? Is there some sort of prerequisite to writing to a file I'm missing?

EDIT: Solved. If the file exists, dbOpenToWrite() will fail.

2A6X1B
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 8th Oct 2011 05:48
If the file already exists, I think it will fail.

The fastest code is the code never written.
Mr Bigglesworth
16
Years of Service
User Offline
Joined: 4th Mar 2008
Location:
Posted: 8th Oct 2011 05:51
You should just use <fstream>

I have always had a much better success using it rather than GDK's built in system.
wtfsven
13
Years of Service
User Offline
Joined: 1st Oct 2011
Location:
Posted: 8th Oct 2011 13:34
Hawk, you're right; I just figured that out a few hours ago. I had no idea, since that completely contradicts the documentation.
Mr. Bigglesworth, I would, but this is a school project. I have to use the library provided. :/

2A6X1B
Red Eye
16
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 9th Oct 2011 01:50
Quote: " I would, but this is a school project. I have to use the library provided. :/
"


If it is a good teacher it would give you a better mark, considering fstream is a native c++ implementation, and it is way cleaner.
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 9th Oct 2011 05:57
Quote: "If it is a good teacher it would give you a better mark, considering fstream is a native c++ implementation, and it is way cleaner."

Implimetation of fstream might not be the best to accomplish certain tasks such as writing a memblock to a file. In that case it's best to use the DGDK stuff.

The fastest code is the code never written.
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 9th Oct 2011 13:04
It still is. Simply use dbGetMemblockPtr and you can write it to the file in one line (just make sure you opened it in binary mode).

[b]
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 9th Oct 2011 15:07
Good to know.

The fastest code is the code never written.
Michael P
18
Years of Service
User Offline
Joined: 6th Mar 2006
Location: London (UK)
Posted: 25th Oct 2011 22:53
Yeah there is no time where using DGDK's file commands is a good idea, they are basically a bad wrapper for fstream anyway.

Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 26th Oct 2011 20:17
dbOpenToWrite used to work here, maybe it is dbFileOpen the one that isn't working...
Oh I read now that edit in the 1st post, so it works after all

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 10th Nov 2011 18:38
I agree - but I ran into a problem that is severely crippling me at the moment - when I use any REAL C++ library fstream, vector whatever.. because all I have is a DarkGDK lib released in "Release Mode" , if I'm trying to use "Debug Mode" all of a sudden I get tons of linker errors about the libcrt file or whatever.. I found on these forums (some where) that is because the code I'm running in debug mode is using one version of libcrt (called libcrtd I think for debug) while DarkGDK uses libcrt (release mode version)...

So just be prepared for this gotcha - maybe latest version has both debug and release libs distributed (which would solve) I don't know.

Good Luck!

Login to post a reply

Server time is: 2024-11-19 06:50:42
Your offset time is: 2024-11-19 06:50:42