|
Your problem is that a CString object does not contain the string itself, only a pointer to the string. When you write your omega object to the file, you only write the pointer, which is then invalid when you read the object back in and try to use it.
--Mike--
http://home.inreach.com/mdunn/
All your base are belong to ME~!
|
|
|
|
|
How does MFC create a CHttpConnection object on the calling processes heap
via the CInternetSession::GetHttpConnection method call? I am trying to
accomplish something similar using my own DLL and all of the object I return
get created on the DLL's heap and when the calling process deletes the object
I get access violations. Anyone know how MFC does this?
Thanks
Brad
|
|
|
|
|
A DLL doesn't have a separate heap. The heap belongs to the process, which is your EXE and all DLLs (and other modules like OCXs) that are loaded as well. So just allocate objects with new.
--Mike--
http://home.inreach.com/mdunn/
All your base are belong to ME~!
|
|
|
|
|
I believe you are wrong. I have a very simple DLL with the following two
classes and code:
#ifdef BF_EXPORTS
#define BF_API __declspec(dllexport)
#else
#define BF_API __declspec(dllimport)
#endif
class BF_API CBar {
public:
CBar( void ) {
m_bFlag = true;
}
private:
bool m_bFlag;
};
class BF_API CFoo {
public:
CFoo( void ) {
}
CBar * MakeBar( void ) {
CBar * cResult = new CBar();
return cResult;
}
};
I have a very simple console application that uses these two classes and
then deletes the new'd objects:
#include <stdio.h>
#include "BF.h"
int main(int argc, char* argv[])
{
CFoo * foo = new CFoo;
CBar * bar = foo->MakeBar();
delete bar;
delete foo;
return 0;
}
When built and run Debug, an assert generated in HeapValidate via
_CrtIsValidHeapPointer when the delete of bar is performed.
Brad
|
|
|
|
|
From the MSDN article "Using the C Run-Time":
[snip]
Section 4: Problems Encountered When Using Multiple CRT Libraries
If an application that makes C Run-time calls links to a DLL that also
makes C Run-time calls, be aware that if they are both linked with one of
the statically-linked C Run-time libraries (LIBC.LIB or LIBCMT.LIB), the
.EXE and DLL will have separate copies of all C Run-time functions and
global variables. This means that C Run-time data cannot be shared between
the .EXE and the DLL. Some of the problems that can occur as a result are:
- Passing buffered stream handles from the .EXE/DLL to the other module
- Allocating memory with a C Run-time call in the .EXE/DLL and
reallocating or freeing it in the other module
- Checking or setting the value of the global errno variable in the
.EXE/DLL and expecting it to be the same in the other module. A related
problem is calling perror() in the opposite module from where the C Run-
time error occurred, since perror() uses errno.
To avoid these problems, link both the .EXE and DLL with CRTDLL.LIB or
MSVCRT.LIB, which allows both the .EXE and DLL to use the common set of
functions and data contained within CRT in a DLL, and C Run-time data such
as stream handles can then be shared by both the .EXE and DLL.
[end snip]
I found that if I compiled the DLL adding the MSVCRT.DLL to the Object/Library modules list in the link General settings, and selected Ignore all default libraries, the problem went away.
|
|
|
|
|
Does anyone know how to combine DirectDraw and CView?
So that I have a CView in which I can use DirectDraw functions.
|
|
|
|
|
How can I convert a CString, to a char* ? Or what is the CString equivalent of the function isDigit()
|
|
|
|
|
CString myCString("1N3");
char* MyStringPointer = (LPCTSTR)myCString;
isdigit(MyStringPointer[0]); // true
isdigit(((LPCTSTR)myCString)[1]); // false
isdigit(myCstring.GetAt(2)); // true
If you want to be ansi/unicode agnostic then use _istdigit.
Endless ways.
-Erik
|
|
|
|
|
none of those worked on my VCPP, and I have the 3rd service pack. It says cannot convert const char* to char*.
|
|
|
|
|
Drake,
It's best to learn C/C++ before trying to program in MFC.
Since all you are doing is checking is digit and not modifying the string, you can put const in front of your char* declaration and the compiler will not complain.
const char* strPtr = (LPCTSTR)myCString;
-Erik
|
|
|
|
|
See CString::GetBuffer(..).
Be sure to call ReleaseBuffer when you're done.
--
Alex Marbus
www.marbus.net
But then again, I could be wrong.
|
|
|
|
|
Hee now than i saw your message..
prev, I got the same problem with the isDigit() function
so I got and create a iIsNum(CString string) function
using VC++ ver 6
BOOL iIsNum(CString string)
{
int strLenght = string.GetLength();
bool _isnum;
CString chr;
for (int i = 0; i < strLenght ; i++)
{
chr = string.Mid(i,1);
if(chr >= "0" && chr <= "9")
_isnum = TRUE;
else
{
_isnum = FALSE;
break; // no use search for other char
}
}
return _isnum;
}
Hope you still can use this function
~~~
|
|
|
|
|
How can I convert a CString, to a char* ?
|
|
|
|
|
CString str("Hello World");
LPTSTR ptr=str.GetBuffer();
.....
.....
str.ReleaseBuffer();
Cheers
Kannan
|
|
|
|
|
I'm doing the printing right now and print all the drawing to the printer. As normal, I'm using CDC in my OnDraw and OnPrint. I want to have a caption on the printing but seems the size is very very very very small. How to change the font type and font size?
|
|
|
|
|
Is there any faster way to let the user to input some text without creating a new dialog box?
For example, print the question on the screen and the user answer it and press ENTER.
|
|
|
|
|
If this is in relation to your printing, you can extend the printing dialog to also ask the question(s) you have in mind, but I don't see why you'd fiddle around with asking a question and not having ANY dialog - you need to put up a static and an edit box at least, why is there a detrimental effect in them being in a dialog ?
You can make the dialog close when you press enter in the text field if you're worried about people having to press OK.
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|
|
I am trying to control MS InterDev 6.0. I want to do relatively simple things like make it save the current document. I am performing this control with many other apps by sending WM_COMMAND messages with parameters I sniffed with Spy++. Also I am finding the windows using the classname.
I've spent some time with Spy++ and cannot determine any messages I could pass to InterDev to make it save a document. Currently I am generating keyboard events to pass control-s to the window. This is really ugly and I would like a cleaner way to do it.
Does anyone know specifically how to get InterDev to save a document?
Generally, does anyone have suggestions of another method of controling apps and how to reverse engineer those techniques?
Thank you for your help. --Adam
--
Adam Solesby
adam@solesby.com
http://solesby.com
|
|
|
|
|
given a face colour for a windows 3d control (e.g. a button) how does one calculate the highlight and shadow colours programatically. I would like to be able to come up with the same values that windos itself callculates when using "display properties/appearance". I suspect that it will involve converting the rgb colour to hsl then doing a calc, then converting back but I need the numbers.
any ideas?
adam
|
|
|
|
|
Use GetSysColor(COLOR_3DLIGHT) or GetSysColor(COLOR_3DSHADOW). No need to perform 'manual' calculations.
|
|
|
|
|
Hi Guys !
I had the following problem !
I had a MFC Program which must start WORDPAD (for printing a Document)
how can i realise this ???
mfg
Joachim
|
|
|
|
|
Maybe ShellExecute can help you.
Grtx,
Berry
|
|
|
|
|
I have a Code which compiles well; But when I build the Exe file It gives me the following Link Errors:
***********************************************************************
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/testbug.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
testbug.exe - 2 error(s), 0 warning(s)
I have NO CLUE What is going wrong and How to Fix it................Please Help me !!
The Code of the program is as follows:
**********************************************************88
#include<iostream>
#include<fstream>
#include<string.h>
#include<stddef.h>
#include<ctype.h>
#include<utility>
// get the STL stuff
#include <vector>
#include <iterator>
// this turns off a useless compiler warning
#pragma warning(disable:4786)
// a namespace is a C++ way of hiding class names.it helps prevent name collisions in large
// projects. "using namespace std" says that you want to use classes that are in the "std" namespace.
using namespace std ;
// same thing here...
using namespace std::rel_ops ;
int main()
{
ifstream infile("in_file");
if(!infile)
{cerr<<"Error, unable to open inputfile";
return -1;
}
else { cout<<"Congrats !!";
return 0;}
};
|
|
|
|
|
See knowledge base articles Q125750 and Q131204 to help you with this problem.
Grtx,
Berry
|
|
|
|
|
Apparently your project settings are not in alignment with what you want to do.
When you created your project, you did not select "Win32 console application".
Since your program contains a main() function and does nothing windows-specific
(that is, displaying windows and stuff), your application is a console application.
Your project settings seem to be "Win32 application" or similar.
In such projects, the main entry point is a function named WinMain() and
*not* main().
Good luck anyway
|
|
|
|