|
Thanks Mike, and do we have any similar function in .net?
?
|
|
|
|
|
I have a class which is compiled to a DLL. When giving out the DLL, i give along the .h, .lib and .dll files.
.h File content (implementation in .cpp compiled to .dll and .lib)
class DLLTESTV_API CDLLtestV {<br />
public:<br />
CDLLtestV(void);<br />
int GetX();<br />
void SetX(int _X);<br />
private:<br />
int x;<br />
};
But, i do not want the end user to know any private members of my Class. Is there anyway
i can hide those? The private members are in the private: block in the .h file and are visible in my class declaration.
I want to ship .lib, .dll and .h like this
class DLLTESTV_API CDLLtestV {<br />
public:<br />
CDLLtestV(void);<br />
int GetX();<br />
void SetX(int _X);<br />
};
I have tried doing so (by deleting manually the private : int x line in the .h file used in a test program), and the programs executes fine but causes an error at the end. Removing that line causes a stack corruption error during runtime (with the compiled DLL in a test program).
Any suggestion how i can hide the private members (users cant modify them anyway, they are private!).
|
|
|
|
|
The way it is done generally is to provide an interface only: make your CDlltestV class inherits from an interface class (IDlltestV for example) which exposes only the public functions as pure virtual:
class DLLTESTV_API IDLLtestV {<br />
public:<br />
CDLLtestV(void);<br />
virtual int GetX() = 0;<br />
virtual void SetX(int _X) = 0;<br />
};
Then in your dll, you simply make CDlltestV inherits from this interface and you provide there the members and implements the functions.
The 'problem' is that you'll need to provide a function to will create an instance of this class and return a pointer to your interface:
DLLTESTV_API IDlltestV* GetClass()<br />
{<br />
return new CDlltestV;<br />
}
But if your code is well written, this shouldn't pose too much problems.
|
|
|
|
|
To Quote Marshall Cline : "Encapsulation is for code, not for people". You shouldn't try to hide it. The statement private says all there is to say. The best way to enforce proper use is to put all public functions into an abstract base class ("Interface"), derive from it, declare the constructor private and create a class factory that only returns pointers to the ABC. But people will allways see what's in there if you give out the headers. See here : How can I prevent other programmers from violating encapsulation by seeing the private parts of my class?[^]
|
|
|
|
|
how about using a privite implementation, aka PImpl ?
in your header you make reference to a private class that is declared and defined in the source file:
in pseudo-code.
class MyClassImpl;
class MyClass
{
private:
MyClassImpl* m_pImpl;
public:
void DoSomething(){m_pImpl->DoSomething;};
};
class MyClassImpl
{
public:
void DoSomething();
protected:
};
|
|
|
|
|
The problem is that the header defines not only the object interface, but also the size.
By building the dll with one header (with private members) and building an exe with another (no private members) you are using a different a sized object in the exe. At best you will experience what you have - runs with error at end. Most likely the program would be corrupting data everywhere.
uus831 wrote: Any suggestion how i can hide the private members (users cant modify them anyway, they are private!).
This isn't true, all non-const data can be modified, private is just the class developer attempting to create a contract with other developers who use the class. Another developer can just mod your header and replace private with public, now they can compile/link without warnings/errors and modify the (originally) private members however they want.
So, your choices:
1. Include a dummy private variable (byte array) that is the same size as all your private/protected members (including padding due to alignment). This can be tricky and is not recommended.
2. Export as an interface, as others have suggested.
3. Export with full header, as most people do/suggest.
[EDIT]
4. As Maximilien suggested, or even easier, just have a pointer to a private state struct.
e.g.
struct Apvt;
class A {
Apvt *pvt;
public:
A( void );
~A( void );
...
};
typedef struct Apvt {
...
} Apvt;
A:: A( void ) { pvt = new Apvt; }
A::~A( void ) { if(pvt) delete pvt; pvt = NULL; } This is actually a fairly common method that i've seen and used before.
[/EDIT]
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Thank you so much guys! Works exactly like I wanted it to! The private struct technique is the easiest. Now i'm going to try the interface way.
Thanks again.
Really appreciated it!!
|
|
|
|
|
LONGLONG Date; //number of 100ns intervals since January 1st 1601 at * 00:00 UTC
How can i convert this to COleDateTime (or some other date structures)
I don't believe in failure. It is not failure if you enjoyed the process.
|
|
|
|
|
... FILETIME Structure Link[^]
I don't believe in failure. It is not failure if you enjoyed the process.
|
|
|
|
|
Hi to all,
in one of my applications ,i have to add a treeview to a combobox,
i searched a lot to find an article on this, but unable to find.
plz friends suggeswt me,or provide the url on how to add treeview to a combobox
thx in advance
Nagaraju
|
|
|
|
|
|
Hi..
I want to write a SMTP protocol using sockets....can any one suggest me.
Thanks
-murad
|
|
|
|
|
Abbas Murad wrote: I want to write a SMTP protocol using sockets....can any one suggest me.
Learn the Simple Mail Transfer Protocol[^] and implement it using sockets.
|
|
|
|
|
|
Hi,
I have a question regarding serial I/O.
...
I have been programming in MFC to interface Serial Ports
in Windows NT in order to read/write them in Overlapped as well as
in non-overlapped mode.
...
It worked fine all the time.
...
But I have a question regarding serial port.
...
That,
1) I open COM1 port in non-overlapped (Blocking I/O) mode
2) I Create a seprate thread, in which I attemp to read five Characters.
using "ReadFile" function.
3) Now, this function will not return unless I get all the five Characters
(As I have forced the "Read Timeouts" and "Write Timeouts" in
COMMTIMEOUTS structure to zeros)
4) But in case if I want to abort without further waiting for the arrival
of characters, I would have to abort the thread "Pre-matureally" ...
5) How can I do this, since the thread is simply blocked in waiting for
characters, as the "ReadFile" function has still not returned.
6) The application window closes, but the Thread keeps on running behind.
...
Basically I want my thread to terminate alongwith when application terminates.
But I dont get it through...
...
I will be very thankful for your assistance ...
...
|
|
|
|
|
There are only two ways for a call to ::ReadFile() on a serial device to return when opened in non-overlapped mode:
1. the device has received the number of bytes you wanted to read
2. there was a timeout due to the COMMTIMEOUTS settings, either there was too much time between two consecutive bytes or the whole operation took too much time to complete
There is no way to get passed this because this is how the system works.
It would be tempting to look at ::CancelIo(), but it can only be used in overlapped mode and by the thread that issued the read request.
--
Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998 "...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above
|
|
|
|
|
Abruptly, you can call the TerminateThread from the main thread.
Or (better) you can handle all that stuff using OVERLAPPED I/O.
|
|
|
|
|
When I use Adobe PhotoShop's Crop Tool. It creates a subwindow helping me to select image scope. The subwindow attract me for its frame line looks moving. And I hope that there will be such a window in my application.
anyone can help me ?
|
|
|
|
|
when we use mouse to select some text on windows?
for example, we select some text in notepad application
i want to get the current selected text,
I does not want to simulate ctrl+c hotkey to copy data to clipboard(read data from clipboard),
i think this is very foolish,
I want to known whether some COM interface for us to use??? thanks again..
|
|
|
|
|
Not sure. But see if GetWindowText() is going to be of any use.
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
|
MAINFRM
<br />
<br />
#include "stdafx.h"<br />
#include "Scribble.h"<br />
<br />
#include "MainFrm.h"<br />
<br />
#ifdef _DEBUG<br />
#define new DEBUG_NEW<br />
#undef THIS_FILE<br />
static char THIS_FILE[] = __FILE__;<br />
#endif<br />
<br />
<br />
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)<br />
<br />
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)<br />
ON_WM_CREATE()<br />
END_MESSAGE_MAP()<br />
<br />
static UINT indicators[] =<br />
{<br />
ID_SEPARATOR,
ID_INDICATOR_CAPS,<br />
ID_INDICATOR_NUM,<br />
ID_INDICATOR_SCRL,<br />
};<br />
<br />
<br />
CMainFrame::CMainFrame()<br />
{<br />
<br />
}<br />
<br />
CMainFrame::~CMainFrame()<br />
{<br />
}<br />
<br />
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)<br />
{<br />
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)<br />
return -1;<br />
<br />
if (!m_wndToolBar.Create(this) ||<br />
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))<br />
{<br />
TRACE0("Failed to create toolbar\n");<br />
return -1;
}<br />
<br />
if (!m_wndStatusBar.Create(this) ||<br />
!m_wndStatusBar.SetIndicators(indicators,<br />
sizeof(indicators)/sizeof(UINT)))<br />
{<br />
TRACE0("Failed to create status bar\n");<br />
return -1;
}<br />
<br />
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |<br />
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);<br />
<br />
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);<br />
EnableDocking(CBRS_ALIGN_ANY);<br />
DockControlBar(&m_wndToolBar);<br />
<br />
<br />
return 0;<br />
}<br />
<br />
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)<br />
{<br />
<br />
return CMDIFrameWnd::PreCreateWindow(cs);<br />
}<br />
<br />
<br />
#ifdef _DEBUG<br />
void CMainFrame::AssertValid() const<br />
{<br />
CMDIFrameWnd::AssertValid();<br />
}<br />
<br />
void CMainFrame::Dump(CDumpContext& dc) const<br />
{<br />
CMDIFrameWnd::Dump(dc);<br />
}<br />
<br />
#endif //_DEBUG<br />
<br />
<br />
<br />
class CMainFrame : public CMDIFrameWnd<br />
{<br />
DECLARE_DYNAMIC(CMainFrame)<br />
public:<br />
CMainFrame();<br />
<br />
public:<br />
<br />
public:<br />
<br />
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);<br />
<br />
public:<br />
virtual ~CMainFrame();<br />
#ifdef _DEBUG<br />
virtual void AssertValid() const;<br />
virtual void Dump(CDumpContext& dc) const;<br />
#endif<br />
<br />
protected:
CStatusBar m_wndStatusBar;<br />
CToolBar m_wndToolBar;<br />
<br />
protected:<br />
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);<br />
DECLARE_MESSAGE_MAP()<br />
};<br />
<br />
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
Hi!!
I am using slider control in my application.
I set JPG image as background for my dialog using CXImage.
How Can I set transparent to slider control background.
Can anyone please give me the solution for this...
Thanks&Regards,
klvin
|
|
|
|
|
Can you try this ?
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (CTLCOLOR_SCROLLBAR == nCtlColor)
{
pDC->SetBkMode(TRANSPARENT);
}
return hbr;
}
|
|
|
|
|
Hi !!
Thanks for the reply.
I tried with OnCtlColor(...)
But,It is not working.
klvin.
|
|
|
|