|
Use include directories? Just specify these in the properties.
|
|
|
|
|
I did add an include for the common folder but how do files in the common folder see the stdafx.h for example in the project directory or is that bad technique.
So, if I include #include "stdafx.h" the files in the common directory can't find this file (duh). I guess I could add a file in the common directory called includes.h and include anything that the common files need.
|
|
|
|
|
Access violations should have nothing to do with your file structure at all.
Are you using threads?
John
|
|
|
|
|
That's what I would of thought as well.
I am not using any threads. Well, I am using MSXML4 using smart pointers so I don't know what's going on in the background nevertheless the project was working just fine. I recently had a working project and decided that I wanted to clean up the code and reorganize the file structure. I added nothing new during this cleaning up process so it can't be anything I added.
I did things like:
Changed this from:
int A,R,G,B;
to this:
struct _Color
{
int A,R,G,B;
};
and
CString Fontname;
CString Fontstyle;
float Fontsize;
int A,R,G,B;
to
struct _Font
{
float Size;
CString Name, Style;
_Color Color;
};
I changed the way I included some of my file around and now the very first CString I get to I get the following error.
First-chance exception in HTPCCORE.exe (MFC42D.DLL): 0xC0000005: Access Violation.
crashing in the = operator
const CString& CString::operator=(const CString& stringSrc)
{
if (m_pchData != stringSrc.m_pchData)
{
crashs here-> if ((GetData()->nRefs < 0 && GetData() != _afxDataNil) ||
stringSrc.GetData()->nRefs < 0)
{
// actual copy necessary since one of the strings is locked
AssignCopy(stringSrc.GetData()->nDataLength, stringSrc.m_pchData);
}
else
{
// can just copy references around
Release();
ASSERT(stringSrc.GetData() != _afxDataNil);
m_pchData = stringSrc.m_pchData;
InterlockedIncrement(&GetData()->nRefs);
}
}
return *this;
}
Makes no sense.
If I were using threads what would the solution be. Oh, I am using VC++6 and I recently installed the latest service pack. Things were still working then as well.
|
|
|
|
|
My thoughts are that you did not initialize something in your first version properly but you were lucky that it did not cause a problem.
John
|
|
|
|
|
That may be the case. I started a new empty project and slowly added in all my files and checking for things like uninitialized variables. It works fine again. I really did not change much beside using a new empty project. Thanks for your responses.
|
|
|
|
|
smesser wrote:
So what is a good approach for separating common files like in my situation?
Exactly what you did. You can also seperate each part (execpt for the main application) into is own library or dll.
John
|
|
|
|
|
The plugin is a dll I need to learn how to put common into a dll. Can you point out a good article?
|
|
|
|
|
My help files are split in 4 .chm (one master, linking to others)... I want to search topic by ids without the user know that the topic doesn't come from the main .chm ?
I used
HtmlHelp(GetDesktopWindow(), HelpPath, HH_DISPLAY_TOC, id);
when I had only one .chm
but now I don't have an idea how to do the same!
thanks
|
|
|
|
|
I am trying to wrap a C API in C++. The problem I am having is that some of the functions in this API are callbacks. When I create functions in a C++ class the calling convention is __thiscall. From each function I created I called the corresonding C function from the API. The problem is that the C function uses the __cdecl calling convention. I get an error when trying to compile
cannot convert parameter 2 from 'void *' to 'void (__cdecl *)(void *)'
Ex.
// this is the callback
void CTest:: Error(void *Param)
{
}
CNew new; // in the CTest class
new.AppCatchError(Error) //this is within the CTest class
void CNew::AppCatchError(void* HandlerFunc)// HandlerFunc a c++ member function
{
//this is the C API function
AppError(HandlerFunc); //error this is looking for a c function __cdecl
}
|
|
|
|
|
If you pass a function pointer along with another function, you need to create a typedef of it's "signature" sorta say.
it'd be something like this:
typedef void (__cdecl *FuncPtr)(void *);
This basically defines a generic function signature, with C declaration and one void ptr argument.
And now use FuncPtr as argument for AppCatchError in order to be able to pass Error() along as a pointer.
Hope this helps.
If you're interested to know more about it, check this out
|
|
|
|
|
Still geting an error
cannot convert parameter 2 from 'void (__cdecl *(void))(void *)' to 'void (__cdecl *)(void *)'
This has to do with the fact that it is a member function. How does this work in C++, if this function was global function there wouldn't be a problem.
|
|
|
|
|
You can do three things:
1) Make the function global
2) Make it static
3) Wrapper functions
|
|
|
|
|
gs1589 wrote:
This has to do with the fact that it is a member function.
Yes, it does. If you want to use it this way the member function must be a static member function.
John
|
|
|
|
|
Error(void *Param) is a member function. Make it static.
// this is the callback
static void __stdcall CTest:: Error(void *Param);
Kuphryn
|
|
|
|
|
Hi,
I have a couple of list views in which I use Custom Draw to get my content on screen. This all works just fine, except for one thing. The uItemState member of the NMCUSTOMDRAW structure is supposed to indicate whether an item is selected or not.
I would test it like:
if( pNMCD->nmcd.uItemState & CDIS_SELECTED)
{
}
Except that always ends up being true, even when an item is not selected. So, right now I'm testing the MFC way with GetItemState, and test for the LVIS_SELECTED bit. But am I just using uItemState in a wrong way or anything? Everywhere I look at on the web it's used in such way..
It's not a big thing, I mean, GetItemState does the job. But I am getting curious why it won't work for me.
|
|
|
|
|
uItemState is only valid for certain draw stages, as specified by the uDrawStage member of NMCUSTOMDRAW .
Software Zen: delete this;
|
|
|
|
|
I want to create CBitmapButton in a dialog with CButton::Create(), but for some reason the button is not visible when I run the app.
I put the following code in CDialog::OnInitDialog()
<br />
VERIFY(m_whiteBtn2.Create("", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_OWNERDRAW, CRect(200, 100,85,48), this, IDC_WHITE_BUTTON2));<br />
<br />
VERIFY(m_whiteBtn2.LoadBitmaps(IDB_WHITE_BUTTONU, IDB_WHITE_BUTTOND));<br />
Does anyone know what might be the problem?
|
|
|
|
|
You might want to try BS_BITMAP ...
Iain.
|
|
|
|
|
|
I've already made it work by using AutoLoad(), but I'm having problems with using CButton::Create().
|
|
|
|
|
In case you don't get your code working, see this article.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
After calling the button's Create(...) method, you must call its ShowWindow(SW_SHOW); method to actually show the window.
Software Zen: delete this;
|
|
|
|
|
hello again,
once an application has been compiled, you can pretty much delete the source code and it will work fine.
how about if i need to get the code for a certain application back - i deleted it by accident.
how can i get the code behind a compiled working application.
thanks for you help guys
g.r.
|
|
|
|
|
Source Control.
Or, perish the thought, maybe even Back Ups.
But in your case, I suspect these aren't going to be suitable.
Chris Meech
We're more like a hobbiest in a Home Depot drooling at all the shiny power tools, rather than a craftsman that makes the chair to an exacting level of comfort by measuring the customer's butt. Marc Clifton
VB is like a toolbox, in the hands of a craftsman, you can end up with some amazing stuff, but without the skills to use it right you end up with Homer Simpson's attempt at building a barbeque or his attempt at a Spice rack. Michael P. Butler
|
|
|
|