|
You have two solutions:
1) Use the pimpl idiom
2) Use the Microsoft export "hack"
1) By pimpl idiom I mean:
class Class {
struct Pimpl;
Pimpl* m_pimpl;
public:
Class();
~Class();
void SetX(int x);
};
struct Class::Pimpl { int x; }
Class::Class() : m_pimpl(new Pimpl)
{
}
Class::~Class() { delete m_pimpl; }
void Class::SetX(int x) { m_pimpl->x = x; }
That also has the benefit to minimize dependencies between sourcefiles. If you change a data member, only the .cpp containing the Pimpl struct will be recompiled - not all other files which include the header file. More on this idiom can be read here: http://www.gotw.ca/gotw/028.htm[^]
2) This hack is non portable AFAIK. On the other hand, exporting C++ classes is non portable as well, so I guess it's not a problem for you. You can read more about it here: http://support.microsoft.com/kb/q168958/[^]
--
Torn from tomorrow's headlines
|
|
|
|
|
As mentioned, the MS hack is the easiest (though non-portable) way.
e.g.
MyArrayT.h (example template class)
template<class TT> class MyArrayT {...};
MyTempExp.h (not really needed)
typedef MyArrayT<long> MyArrayLong;
MyTempExp.cpp (this is the important part)
template class __declspec(dllexport) MyArrayT<long>;
This will create exports of all methods/data for MyArrayT<long>.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
I need source-code or tool to save bitmap buffer to gif file programmatically in VC app, user can specify transparent background color when saving.
which class or tool can help to do that?
|
|
|
|
|
Best option i think you use GDI+!
so first try,
http://www.codeproject.com/vcpp/gdiplus/gdi__and_mfc.asp
for initalize GDI+ then try to search MSDN , encoder & decoder :
for example if you wanna convert bmp to gif this code help you:
<br />
INT GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{<br />
UINT num = 0;
UINT size = 0;
<br />
ImageCodecInfo* pImageCodecInfo = NULL;<br />
<br />
GetImageEncodersSize(&num, &size);<br />
if(size == 0)<br />
return -1;
<br />
pImageCodecInfo = (ImageCodecInfo*)(malloc(size));<br />
if(pImageCodecInfo == NULL)<br />
return -1;
<br />
GetImageEncoders(num, size, pImageCodecInfo);<br />
<br />
for(UINT j = 0; j < num; ++j)<br />
{<br />
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )<br />
{<br />
*pClsid = pImageCodecInfo[j].Clsid;<br />
free(pImageCodecInfo);<br />
return j;
} <br />
}<br />
<br />
free(pImageCodecInfo);<br />
return -1;
<br />
}<br />
<br />
<br />
<br />
CLSID encoderClsid;<br />
Status stat;<br />
Image* image = new Image(L"Bird.bmp");<br />
<br />
GetEncoderClsid(L"image/gif", &encoderClsid);<br />
<br />
stat = image->Save(L"Bird.gif", &encoderClsid, NULL);<br />
<br />
<br />
<br />
delete image;<br />
<br />
|
|
|
|
|
& for transparent background you can search : ImageAttributes class & ColorMatrix class
first create ColorMatrix ! then with SetColorMatrix assign that to instance of ImageAttribute then
draw both of image ! so you can see it transparent background!
|
|
|
|
|
there are many gif related classes on CP, but most of them are for reading gif files. You will find that saving a gif file is very problematic due to the LZW compression and the patenting issues. Must you use a gif format?
Take a look at this article[^]. Its for displaying gif images to a CStatic control. But within the source code are functions for reading a gif directly from the file. You could try reverse engineering it to save instead.
|
|
|
|
|
waldermort wrote: You will find that saving a gif file is very problematic due to the LZW compression and the patenting issues.
all of the relevant LZW patents expired years ago.
|
|
|
|
|
Oh, really? I didn't realize. So I'm guessing there are no reprocussions to loading and saving gif files now?
|
|
|
|
|
waldermort wrote: So I'm guessing there are no reprocussions to loading and saving gif files now?
that's right
|
|
|
|
|
I'm making a custom wizard to make a DLL project. I'm having a simple problem. I create 2 files, a header and a cpp file. In the project that the wizard creates, I want these files to end up in the Project's 'Source Files' folder. This isn't a physical directory on the disk, mind you. IOW, looking into the .vcproj file for the project, scanning down to the directory structure i'm finding this:
<br />
...<br />
< Filter<br />
Name="Source Files"<br />
Filter="txt"><br />
< /Filter><br />
< File<br />
RelativePath=".\PlugInImpl.h"><br />
< /File><br />
< File<br />
RelativePath=".\PlugInImpl.cpp"><br />
< /File><br />
...<br />
when what i want to see is this:
<br />
...<br />
< Filter<br />
Name="Source Files"<br />
Filter="txt"><br />
< File<br />
RelativePath=".\PlugInImpl.h"><br />
< /File><br />
< File<br />
RelativePath=".\PlugInImpl.cpp"><br />
< /File><br />
< /Filter><br />
...<br />
|
|
|
|
|
hmm the code snippet didn't come out like i wanted too there. well, you get my drift hopefully. i need the File elements to be nested in the Filter element. is this done through the javascript file in my custom project? if so, how?
|
|
|
|
|
Hi, I have a question about memory allocation for a CSafeArray, and in general.
Let's say I have a local variable defined like this:
void dosomething()
{
CSafeArray data;
data.CreateOneDim(1);
}
So now I've allocated memory for the CSafeArray. Does this mean I have to deallocate that memory once I'm done with it, or will this memory be automatically deallocated after the variable goes out of scope because it's locally defined? I always thought this would allocate heap memory and you'd have to manually deallocate but I just want to make sure.
Thanks!
Kelly Ryan
|
|
|
|
|
COleSafeArray's destructor takes care of that for you, so long as you haven't detached the SAFEARRAY object from it.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Before now I used: h=open(....- command and seek/tell for positioning inside file
Now I use: hFile=CreateFile(..... command.
How to position inside file? Will seek/tell work ?
|
|
|
|
|
Monin D. wrote: How to position inside file? Will seek/tell work ?
No. fopen returns a FILE pointer. CreateFile returns a file HANDLE. Passing a HANDLE to any of the FILE operations will fail.
You can find a list of all the methods you can use with the file HANDLE you get from CreateFile here.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
|
Thank you very much, it helps me.
|
|
|
|
|
after use CreateFile that return hFile
you can declare CFile m_fFile(hFile) & then use
m_fFile.Seek....
if you wanna work with in text mode you should use CStdioFile instead
of CFile .
|
|
|
|
|
how seprate client area of application from frame window in MDI?
is way is correct sepreate CChildFrame ???
alternative way i hear is :
create window with WS_OVERLAPPED! but when
i try this:
<br />
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)<br />
{<br />
cs.style |= WS_OVERLAPPED;<br />
if( !CMDIFrameWnd::PreCreateWindow(cs) )<br />
return FALSE;<br />
<br />
return TRUE;<br />
}<br />
there is nothing happen.
Best Regards.
MJM
|
|
|
|
|
mostafa_pasha wrote: seprate client area of application from frame window in MDI?
Please be more specific on what you want to do.
Best,
Jun
|
|
|
|
|
my project is MDI !
i have two view class , CStartPageView and CImageProcessingView !
first application execute OnDraw of CStartPageView because i create document
when OnFileNew fucntion run i create some object as CImagePorcessingView .when create new
page something that i use in CStartPageView::OnDraw show in client area of CImageProcessingView .
i mean every thing i draw in page has affect in another page!although the client area (to view class) is seperable.
<br />
m_pDocTemplate = new CMultiDocTemplate(<br />
IDR_ImageProcessingTYPE,<br />
RUNTIME_CLASS(CImageProcessingDoc),<br />
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CImageProcessingView));<br />
if (!m_pDocTemplate)<br />
return FALSE;<br />
AddDocTemplate(m_pDocTemplate);<br />
<br />
m_pDocTemplateStartPage = new CMultiDocTemplate(<br />
IDR_ImageProcessingTYPE,<br />
RUNTIME_CLASS(CImageProcessingDoc),<br />
RUNTIME_CLASS(CChildFrame),<br />
RUNTIME_CLASS(CStartPageView));<br />
if (!m_pDocTemplateStartPage)<br />
return FALSE;<br />
AddDocTemplate(m_pDocTemplateStartPage);<br />
<br />
in OnFileNew:<br />
CDocument* pDoc = m_pDocTemplateStartPage->OpenDocumentFile(NULL);<br />
<br />
<br />
pDocTemplate->OpenDocument(BULL);<br />
<br />
|
|
|
|
|
mostafa_pasha wrote: in OnFileNew:
//create document that class view is CStartPageView
CDocument* pDoc = m_pDocTemplateStartPage->OpenDocumentFile(NULL);
// & for CImageProcessingView is
pDocTemplate->OpenDocument(BULL);
There are problems in your code. Try this in OnFileNew():
CImageProcessingDoc* pDoc = (CImageProcessingDoc*)m_pDocTemplate->OpenDocumentFile(NULL);
CFrameWnd* pNewFrame = m_pDocTemplateStartPage->CreateNewFrame(pDoc, NULL);
if (pNewFrame != NULL)
{
m_pDocTemplateStartPage->InitialUpdateFrame(pNewFrame, pDoc);
}
Best,
Jun
|
|
|
|
|
I am over-riding operator new [] so that when an array of "Objects" is created they contain information about adjacent items in the array. I am getting the following error....
c:\Visual Studio Projects\JLib\main.cpp(149): error C2661: 'Object<T>::operator new[]' : no overloaded function takes 3 arguments
The following code results in the above comilation error.
Object<double>* objects;
objects = new Object<double>[5]; // <- error occurrs here
delete [] objects;
If anyone knows what is going on I would very much appreciate an explanation.
Here is the relevant declarations and definitions...
#pragma once
#include <new>
using namespace std;
template <typename T> class Object{
public:
//CONSTRUCTORS ETC ETC ETC
void* operator new[](size_t size) throw(bad_alloc);
void* operator new[](size_t size,const nothrow_t&) throw();
void operator delete[](void* ptr) throw();
void operator delete[](void* ptr,const nothrow_t&) throw();
//OTHER STUF
};
template <typename T> void* Object<T>::operator new[](size_t size) throw(bad_alloc){
Object<T>* data = 0;
if ( (data = ::operator new[](size){
//ommitted for brevity
}
return data;
}
template <typename T> void* Object<T>::operator new[](size_t size,const nothrow_t&) throw(){
Object<T>* data = 0;
if ( (data = ::operator new[](size,const nothrow_t&)) ){
//ommitted for brevity
}
return data;
}
template <typename T> void Object<T>::operator delete[](void* ptr) throw(){
::operator delete [] (ptr);
ptr = 0;
}
template <typename T> void Object<T>::operator delete[](void* ptr,const nothrow_t&) throw(){
::operator delete [] (ptr,const nothrow_t&);
ptr = 0;
}
|
|
|
|
|
With GCC, the only error I get in your code is caused by the following (in bold):
template <typename T> class Object{
public:
void* operator new[](size_t size) throw(bad_alloc);
void* operator new[](size_t size,const nothrow_t& nt) throw();
void operator delete[](void* ptr) throw();
void operator delete[](void* ptr,const nothrow_t& nt) throw();
};
template <typename T> void* Object<T>::operator new[](size_t size) throw(bad_alloc){
Object<T>* data = 0;
if ( (data = ::operator new[](size){
}
return data;
}
template <typename T> void* Object<T>::operator new[](size_t size,const nothrow_t& nt) throw(){
Object<T>* data = 0;
if ( (data = ::operator new[](size, nt)) ){
}
return data;
}
template <typename T> void Object<T>::operator delete[](void* ptr) throw(){
::operator delete [] (ptr);
ptr = 0;
}
template <typename T> void Object<T>::operator delete[](void* ptr,const nothrow_t& nt) throw(){
::operator delete [] (ptr, nt);
ptr = 0;
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi,
I have problems reading values from a text file into an array. The first problem is reading the data from the file and the other is about data type conversion.
The values in a textfile are arranged vertically, like in a column:
0
1
0
1
1
0
0
1
.
. and so on. There is only 1 vertical column of numbers in the textfile.
I used a loop below to read the values from the file into an array:
while( inClientFile >> values) //inClientFile is an ifstream object.
cout<<.......<
|
|
|
|