|
jDawwg wrote:
0 errors, 0 warnings.
why?! why?! why!! ! ! !
Your code has no syntax errors.
Why it crashes is impossible to tell when you don't post the your code that crashes!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
sorry
heres the code
......
int len;
int result;
char c2[255];
char c3[]="\0";
char c4[]="";
<br>
AfxMessageBox("Starting The Bouncer!");
<br>
HENV hEnv = NULL;
HDBC hDBC = NULL;
HSTMT hStmt = NULL;
UCHAR szDSN[SQL_MAX_DSN_LENGTH] = "cplusmysql";
UCHAR szUID[10] = "xxxx";
UCHAR szPasswd[10] = "xxxx";
UCHAR szModel[128];
SDWORD cbModel;
RETCODE retcode;
<br>
SQLAllocEnv (&hEnv);
SQLAllocConnect (hEnv, &hDBC);
<br>
retcode = SQLConnect (hDBC, szDSN, SQL_NTS, szUID, SQL_NTS, szPasswd, SQL_NTS);
<br><br>
BOOL freeResult, runTimeLinkSuccess = FALSE;
HINSTANCE dllHandle = NULL;
BounceCheckType BounceCheckPtr = NULL;
dllHandle = LoadLibrary("bBounce.dll");
<br>
BounceCheckPtr = (BounceCheckType)GetProcAddress(dllHandle,"BBBOUNCECHECK");
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
CFileInfoArray fia;
fia.AddDir(
m_spoolpath,
"*.*",
TRUE,
CFileInfoArray::AP_SORTBYNAME | CFileInfoArray::AP_SORTASCENDING,
FALSE
);
for (int ji=0;ji<fia.GetSize();ji++) {
ifstream is;
is.open (fia[ji].GetFilePath(), ios::binary );
is.seekg (0, ios::end);
int length = is.tellg();
is.seekg (0, ios::beg);
char * c1 = new char [length+1];
is.read (c1,length);
is.close();
c1[length+1] = '\0';
if(NULL != dllHandle)
{
if (runTimeLinkSuccess = (NULL != BounceCheckPtr))
{
result = BounceCheckPtr(*c1, *c2, len, *c3, *c4);
}
}
UCHAR szSqlStr[128];
if (result == 1) {
sprintf((char*)szSqlStr,"INSERT into bouncetest Values ('HB', '%s')",c2);
SQLAllocStmt (hDBC, &hStmt);
SQLPrepare (hStmt, szSqlStr, sizeof (szSqlStr));
SQLExecute (hStmt);
SQLBindCol (hStmt, 1, SQL_C_CHAR, szModel, sizeof(szModel), &cbModel);
SQLFetch (hStmt);
SQLFreeStmt (hStmt, SQL_DROP);
}
delete[] c1;
}
freeResult = FreeLibrary(dllHandle);
}
SQLDisconnect (hDBC);
SQLFreeConnect (hDBC);
SQLFreeEnv (hEnv);
AfxMessageBox("Finished Sorting Bounces");
|
|
|
|
|
...
char * c1 = new char [length+1];
is.read (c1,length);
is.close();
c1[length+1] = '\0';
... The last line should be
c1[length] = '\0'; This is the first thing I've noticed on a quick review, maybe some more errors are still lurking in the code.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
changed that to what you suggested, still crashes.
|
|
|
|
|
If you could put a breakpoint in at the start of the function, and then Step through the code to find out where the program bombs it would be a lot of help for us to be able to find the bug.
|
|
|
|
|
did that,
it dies at
delete[] c1;
also, i will send anyone who needs a better look the project files if you need them.
|
|
|
|
|
sprintf((char*)szSqlStr,"INSERT into bouncetest Values ('HB', '%s')",c2); c2 is not initialized to anything, this is faulty. Moreover, szSqlStr is not given space enough to accomodate the maximum string possible, approx. equal to 255 plus some 50 chars.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
c2 is initialized. at the beginning , it is initialized to contain nothing. its just storage space for the API to write into.
at the point you are referencing to in my code, c2 contains a value that was given to it via the API function.
thanks for the suggestion , although it is not the problem. Also, szSqlStr has enough space for my needs, why do you suggest it to be bigger?
|
|
|
|
|
c2 is initialized. at the beginning , it is initialized to contain nothing. its just storage space for the API to write into.
By "the API" you mean that pointed to by BounceCheckPtr ? What does this API do? Also, have you checked BounceCheckPtr is not null?
Also, szSqlStr has enough space for my needs, why do you suggest it to be bigger?
Well, c2 is 255 chars: without further info, seems reasonable that, under some ocassions, the strings stored in it can get near that maximum size, wich will overflow a 128 chars szSqlStr .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
c2 is initialized. at the beginning , it is initialized to contain nothing. its just storage space for the API to write into.
By "the API" you mean that pointed to by BounceCheckPtr? What does this API do? Also, have you checked BounceCheckPtr is not null?
Yes, and its not null..The API determines status of a file. Im passing the contents of the file to the API via C1.
The API writes a string to c2 and returns a value as the status code of the kind of file it analyzed.
Also, szSqlStr has enough space for my needs, why do you suggest it to be bigger?
Well, c2 is 255 chars: without further info, seems reasonable that, under some ocassions, the strings stored in it can get near that maximum size, wich will overflow a 128 chars szSqlStr.
oh , ok... i see what you mean now, but i know that the c2 is only going to be between 10 - 30 charactors. really i guess i could clean it up a bit since i dont need the extra space, but i wasnt really worried about it... i was trying to figure out the mystery bug.
just to be sure tho, now that i see what you meant i tried setting szSqlStr to 400 ,still compiles 0 errors, 0 warnings, but im also still getting the mystery bug.
also since i know its the next logical concern, its also definetly not the API. The same .dll file for the API is working perfectly with a program i developed w/ VB.
|
|
|
|
|
Im passing the contents of the file to the API via C1.
Given the expression
BounceCheckPtr(*c1, *c2, len, *c3, *c4); seems what you're passing is not c1 , but rather the character c1[0] , unless the function accepts char& s or something like that. Is that the case? If not, could it be you meant to write this?
BounceCheckPtr(c1, c2, len, c3, c4); (Excuse me if I'm saying nonsense.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
You mentioned in one of your threads that it crashes on the line delete []c1.
If that is so then can you see through your debugger what is in c1 at the time of the delete?
Also, between
char * c1 = new char [length+1]; and the delete the only place c1 is used seems to be
result = BounceCheckPtr(*c1, *c2, len, *c3, *c4);
So comment this line out and then see if it crashes at delete[] c1.
If not then it is most like the BounceCheckPtr which is screwing up on the memory. It may be deleting what is c1 before you can delete c1.
|
|
|
|
|
Would anyone know how to write to a .rtf file (rich text), as well as change the color/face of written text, etc... I'm looking to make a log file with some different colors and fonts. Thanks!
|
|
|
|
|
You want to know RTF?
If so, I may have a suggestion for you. Create a Word document that will look like the log files you want to have. Then save the document in RTF and open the file in text mode and see the RTF formatting.
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
You can find the RTF 1.6 specification here[^]. It's very easy to follow and you should not have any difficulty. If you want to see how an RTF document looks like, write one in Wordpad (not Word, the RTF it generates is too bloated), and then open it in notepad to see how it looks like. Then if you read it side by side with the RTF spec, you will find it much easier to follow.
Regards,
Rohit Sinha
|
|
|
|
|
... COM threading models? (apartment, free, single, multi, both)
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
Read the following:
http://www.codeguru.com/activex/COMApartments1.html
http://www.codeguru.com/activex/COMApartments2.html
|
|
|
|
|
Tx for the pointers
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
I am developing and application in VisualC++ 6.0 and I want the interface to
be in Greek.
I have created all the items of the interface (doalogs menus etc) in Greek
and the application works fine.
However all the Windows dialogs (such as the Open file dialog) appear in
English.
Does anybody knows how could I make these dialogs to appear in Greek ?
(Without having to code them from scratch)
Thanks
Dionysis photeinos@lfme.chemeng.upatras.gr
|
|
|
|
|
They will appear in Greek when the user is running a Greek version of Windows.
Chris Richardson
Programmers find all sorts of ingenious ways to screw ourselves over. - Tim Smith
|
|
|
|
|
Thanks for the answer.
Is it possible however the dialogs to appear in Greek even if the user has the English version of Windows (I am sure this can be done somehow since MS Office (Greek) does it irrespectively of the Windows version, but I do not know how)
Dionysios photeinos@lfme.chemeng.upatras.gr
|
|
|
|
|
You need to change the regional and/or locale settings for the user.
( look in the "Regional Options" control panel. )
Max.
|
|
|
|
|
Has anyone ever programmed an application using a project/workspace model. I am writing an MFC / MDI applicaiton and I need to replicate the same idea that VS uses. The user will be working with a collection of documents. Are there any articles / tutorials that anyone knows of?
Ryan Baillargeon
|
|
|
|
|
Ryan B. wrote:
ever programmed an application using a project/workspace model
Yes, I'm currently doing this.- The app I'm working on consumes XML files. The "project" file is just another XML file that refers to the files in the project, as well as some project-wide properties. I use Xerces to parse XML.
- But you don't have to do this using XML - a simple approach is to use .INI files that basically do the same thing.
- A third approach is to represent the "project" object using a binary format that's serialized by your app. This is the least user-friendly way to represent a project but may be appropriate for your app.
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
What's the problem? Create CProjectDoc class derived from CDocument, create CProjectDocTemplate from CDocTemplate. The document tree is your project view. Then you are creating some interface for you class, something likes as
void AddToProject(LPCTSTR szFileName)
void RemoveFromProject(LPCTSTR szFile) and etc.
The project is a simplest type of document I have ever seen.
Then, workspace's scheme: If you want use same tree for all open projects, you must refuse to use view in CProjectDoc. Point to MFC that you document has no any views
void CProjectDocTemplate::InitialUpdateFrame(CFrameWnd* pFrame, CDocument* pDoc,BOOL bMakeVisible)
{
pFrame->DestroyWindow();
}
and create separate window (of course, docked to a hair's breadth as microsoft - chief of fashion) and scan all projects and show their contents as you wish.
I had once similar project and i don't mind to share it with you, but it is simpler to make it on its own than to ransack some thousands lines of foreign code
|
|
|
|
|