|
Hello,
I have an DLL without using MFC.
This DLL is called from an EXE.
Now I Have the Problem when I am allocating with new:
int lenght = 10;
char * space = new char[lenght];
This don' t work, he destroyed the heap.
Must I do something because of memory ?:
AFX_MANAGE_STATE(AfxGetStaticModuleState());
- But this don't work because I don't use MFC in the DLL
What can I do?
Thanx
Dirk from Germany
|
|
|
|
|
|
no, but the variables are wrong
|
|
|
|
|
Which variables ?? What are you talking about ? Try to be more explicit because otherwise we won't be able to help you. One thing: I think that your problem has probably nothing to do with the fact that this is a dll (it's just a guess) so don't focus on that problem only.
|
|
|
|
|
What do you mean by "the variables are wrong?" Does new return a valid pointer?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Like others, I have no idea what you are asking, however, I think what Chris was trying to get at is that you must be careful how you allocate and deallocate memory between DLL/EXEs.
If your software is using CRTL linked statically, then the EXE and DLL will be using different heaps. Thus if you allocate memory in a DLL and return a pointer to that memory to your EXE, you must then invoke a routine in the DLL to free the memory. Otherwise the EXE will try to free that memory back to its heap that doesn't know about the memory. There are other ways to avoid this such as using the process heap or CoTaskAlloc from OLE/COM. That gets around the problem by using a process wide, well know allocation system that everyone in the process has access to.
Another common problem is improperly declared function prototypes. For example, if your EXE defines your routine as using C++ calling convention but it is really using __stdcall, then bad things will happen. The stack won't be properly managed and variables will appear not to be assigned properly back in your EXE.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Is there any way of making a file dialog a member of a property sheet (just like the one in MS VB6)?
Plz help!
Live long and in prosper
johny74656@gmail.com
|
|
|
|
|
Yes, there is! I've done this on a regular dialog, I don't have much experience with property pages, but I think it will work.
Change the id of the dialog that you use for your property page to IDD_FILEOPEN_EX.
Delete the OK and Cancel buttons.
Select 'Clip Siblings' and 'Clip Children' in the dialog's properties.
Create a static control and change it's id to "stc32" (no quotes).
In your Resource.h file, delete the definition for stc32.
"stc32 is a constant #defined in dlgs.h, so #include dlgs.h in your .rc file.
the file dialog should now show up in place of the static control on that dialog.
My articles
www.stillwaterexpress.com
BlackDice
|
|
|
|
|
Thx, this works!
Live long and in prosper
johny74656@gmail.com
|
|
|
|
|
Hi,
Is this answer still valid while using Visual Studio 2019 ?
The id IDD_FILEOPEN_EX does not exists.
Do I need to include another RC file if I include dlgs.h ?
Thanks.
I'd rather be phishing!
|
|
|
|
|
Hi all!
I have a .lib file which has all the necessary functions which are written in ANSI C. I wanted to use these functions in C#. So I decided to include and use them in a class library file which is to be written in C++ (VS.NET-Class library proj., right? ), then import this class library to my real C# project. So,I have inluded all the include files, library file to my project. But when I try to compile it I end up with the error:
""error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup""
my .h file:
// uFWrapper.h
#pragma once
public __gc class uFWrapperClass
{
public:
uFWrapperClass();
~uFWrapperClass();
void TestFunc();
};
my .cpp file:
// This is the main DLL file.
#include "stdafx.h"
#include "uFWrapper.h"
#include <stdio.h>
using namespace System;
#include "allapi.h" //Necessary inc
#include "log.h" //files
#include "serial.h" //for functions
#include "command.h" //in
#include "config.h" //.lib
#include "module.h" //file
#if defined(TOOL_WIN32)
#define NOGDI
#include <windows.h>
#endif
uFWrapperClass::uFWrapperClass() //construct
{
}
uFWrapperClass::~uFWrapperClass() //destruct
{
}
void uFWrapperClass::TestFunc()
{
int rangeStart = 0x990;
int rangeEnd = 0x999;
UAIdentify(&rangeStart, &rangeEnd); //when this line is include
//i end up with error. This func is in .lib
}
What am I doing wrong? 
|
|
|
|
|
Alper KARS wrote:
But when I try to compile it I end up with the error:
""error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup""
Try changing the substystem in the linker options from Console (/SUBSYSTEM:CONSOLE) to Windows (/SUBSYSTEM:WINDOWS).
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
I have also tried it. But it did not worked for me I think the problem is releated to the .lib file I am trying to use. It seems to be compiled with VS6. In VS6 we could import .lib files to the project from the "Add File..." menu. Is there some way to import .lib files in VS.NET to the VC++ projects? As I have read there is noway to import .lib files to C# projs. (Correct, right?)And thanks for your suggestion by the way.
|
|
|
|
|
I am a VC user, now I use VC6.0, but this many a day , I am troubled by the Visual C++ 6.0 IDE's BOOKMARK question.
As you know ,you can use short cut key <Alt> + F2 to add a bookmark to your project, or you can use short cut key <Ctrl> + F2 to add a color marked bookmark to your project. I am used to the first method to add a bookmark to my VC project.
But long ago , I have sadly found that I couldn't add any bookmark to my project! I use short cut key<Alt> + F2 to activate the "bookmark" dialog, I input the name of my bookmark, such as MyBookMark, and then I click "Add" button to add a new bookmark to my project ,but unfortunately, the below bookmark list has no reflection, i.e, my newly added bookmark can't be seen in the bookmark lists now! however I do, I only find that I can't add any new bookmark to my project!!!
Why this happened ??? I am eager to know the reason and how to solve the troublesome problem.
no pains no gains.
|
|
|
|
|
This is a known issue. Bookmarks will work for the duration of the file/project. Once the file containing the bookmark or the project is closed, the bookmark(s) goes away.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
A known issue ? I want to know whether some progress has been made for this subject in VS.NET 2003
or later version of VS ? Is there really no better way to solve this bug ? In the days when computer technology has been upgrated rapidally, I think such technique question is out of question for so famous company ---MICROSOFT , but why Microsoft hasn't correct this troublesome bug??? puzzling...
Hold up.
|
|
|
|
|
It is really a troublesome bug, many people can't bother it and saying it is so big a bug of MICROSOFT.
|
|
|
|
|
Hi,
I'm converting a project originally written in VC++ 5.0 using MFC. This framework tends to use the uppercase BOOL, TRUE and FALSE for boolean type. The later frameworks include the lowercase bool, true and false as the boolean type. You can't use them together or you will face compiler warnings about performance drop due to converting.
So the question is simple: What to use?
Whats the difference?
Wich is better, and on what field?
Regards,
Kurt Pattyn
codito ergo sum
|
|
|
|
|
small 'bool', its a primitive data type like int,char..etc and accepts only 0 and 1 ... anything above 1 say..2,3,4 taken as 1 only.
BOOL is basically of int type so accepts any values other than 0 and 1..
i think its better to use bool.
hey this is my finding!!.. wait for better responses..
V
|
|
|
|
|
BadKarma wrote:
Whats the difference?
bool is a type builtin C++ (standarized) and BOOL is defined by Microsoft and it's an int (defined in 'windef.h'). An important difference is their size: if you perform a "sizeof" for a bool, it's 1, and in a win32 platform a BOOL has 4 bytes.
BadKarma wrote:
So the question is simple: What to use?
Depends on what you need, if you need something more portable or just a binary variable I'd choose bool if you need a wide range of values then BOOL.
BadKarma wrote:
Wich is better, and on what field?
I prefer bool because it's a c++ standard and when I need a wide range of values I use an int.
Marc Soleda.
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
marcdev wrote:
...if you need a wide range of values then BOOL.
By its very definition, a boolean variable only has two values: 0 and 1. Anything beyond that and you no longer have a boolean variable.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Yep !!! Completely agree
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
In theory yes, but in practice no. Anytime you are using a non-Boolean to represent a Boolean value, you have to be careful how you test for TRUE or FALSE. For example "if (x == TRUE)" is a VERY bad idea since it yields different results than "if (x)".
Now using this information that a BOOL can have four billion different values and returning more results than just TRUE(!=0) or FALSE(==0) is a bad bad thing. (Which is the case I am sure you are referencing.)
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
well actually you can convert them.
The main difference is that a BOOL is actually an integer (4 bytes I think) and TRUE and FALSE are defined values to 1 and 0 respectively.
a bool is a class I think, where the data integrety (true/false) is forced more then the BOOL datatype.
(a little warning: bool can have a sort of tri-state, never use something like the following:
bool mybool;<br />
<br />
<br />
if(mybool == true){
}<br />
else{<br />
}
but use
if(mybool){
}<br />
else{<br />
/code<br />
}
)
both types are used often. BOOL is especially used on structures like:
BOOL myBOOL;<br />
<br />
if(myBOOL == TRUE){<br />
<br />
}<br />
else{<br />
if(myBOOL == 3){<br />
<br />
}<br />
else{<br />
}<br />
}<br />
}
I'll leave it up to you whether you find this good or bad design.
I hope this helps you a bit.
good luck!
No hurries, no worries.
|
|
|
|
|
In your MFC code, stick to BOOL. For everything else (within reason), move towards bool.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|