|
You cannot use the LPSTR datatype if you want your COM objects to be portable outside of C++. You will need to use the BSTR datatype.
Here is a little bit of information about BSTRs.
They are UNICODE strings, so you will have to use the ATL conversion macros to convert between your ansi single character string and the wide char UNICODE string in ATL. Lookup A2W in MSDN and you will find some info about it.
A BSTR is special in the fact that it contains the size of the BSTR encoded in its format. When you deal with a BSTR you are given a pointer to the string portion of the BSTR. However, the 4 bytes preceding that pointer contain the size of the BSTR.
example:
pointer
|
size | string data wide chars
4 bytes V 12 bytes, as the size fild indicates
[12] [\0H\0e\0l\0l\0o\0\0]
You can also use the CComBSTR class in ATL to manage your BSTR variables for you, it simplifies things a lot.
You will also want to become familiar with the ::SysAllocString and ::SysFreeString functions. These are the functions that you will use to allocate a new BSTR.
good luck
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Hi,
Thanx for the reply.
Actually I want to pass a string as a paramter from my
ASP code (in the ACTIVEX-ATL component) and in the
component I am using the parameter as a string for
some purpose where I want a char * type
What should i do
Sameer
|
|
|
|
|
Hello All,
I am currently unable to print / print preview properly from my SDI application. I am using a class derived from CSplitterWnd to split my screen up into 4 windows. The left hand window may be switched between 3 different views. I can print when viewing my default view (defined in the document template), but when viewing either of my other views (all derived from CView), selecting Print from the menu does not do anything...
In which class should I define my printing events (i.e. OnBeginPrinting etc) so as to be able to print no matter which view is on display? Is there an easy solution to this?
Thanks in advance. Any help with this will be greatly appreciated
Steve
|
|
|
|
|
|
Thanks Jonathan. This is exactly what I was looking for. Great advice!
Steve
|
|
|
|
|
Hi, pals!
I want to add a shortcut of my program to the
toolbar of IE. Can you show me a simple sample
codes about how to do it?
Best regards,
George Ma
|
|
|
|
|
Enjoy.
http://www.codeproject.com/atl/ietoolbartutorial.asp
==============
www.design.kg
|
|
|
|
|
Thanks, Karavaev pal!
It is a nice article!
Have a nice day,
George Ma
|
|
|
|
|
how to send a virtual key in a service when the Winlogon desktop is the input desktop?
|
|
|
|
|
Hi.
I am trying to implement a basic static toolbar. Here is the design.
- create a dialog box
- add a button (just consider one button for now)
- use CDialogBar to create the dialogbar at construction
- use GetDlgItem(IDC_Button) to get a pointer to the button
Okay. The design above works well. I have two major problems. First, the button does not look like a normal button. The button looks flat and is out of focus. Secondly, I am not sure where to add the message handler for the button.
What I have done is difficult to explain. I hope the brief explanation above is enough. Here is a simple code for it.
-----
CDialogBar m_MyDlgBar;
CButton *m_pButton;
int CMainFrame::OnCreate()
{
...
if (!m_MyDlgBar.Create(this, IDD_MYDLG, CBRS_BOTTOM, IDD_MYDLG))
{
TRACE0("Panel creation failed");
return -1;
}
m_pButton = reinterpret_cast<cbutton *="">(m_MyDlgBar.GetDlgItem(IDC_BUTTON));
ShowControlBar(&m_MyDlgBar, TRUE, FALSE);
-----
So basically, I need to somehow set the button to look like a normal button. Secondly, I need to know where to add a message handler for the button.
Thanks,
Kuphryn
|
|
|
|
|
Okay. The solution is to update the button with ON_COMMAND_UPDATE.
Kuphryn
|
|
|
|
|
Does anyone know of a good freeware source code printing program. I use to have a great program, but have recently re-imaged my machine and can't remember the programs name. If anyone can recommend a good utility it would be most appreciated.
- SAK
|
|
|
|
|
http://sources.redhat.com/sourcenav
|
|
|
|
|
I have a few issues with this. I haven't changed anything from the standard File->Open message handler. My app crashes if I try to select File->Open without saving or performing some other file operation first. If I open a file, I can't say File->Open until after I have either closed the current file or saved it or something like that. I'm not sure why this is happening since I haven't touched any of that code. Does anyone have any thoughts about where I can look to try to figure this one out?
|
|
|
|
|
A little more info. It looks like I'm having a problem getting junk data in a lot of my variables in the app. for instance, the filename string being passed as "filename" to the DoPromptFileName procedure used to open the Open File dialog contains the maximum (260) possible number of characters in it. They are junk characters, though. What's weird is that the informaion is placed in the variable upon declaration of the variable. Any ideas. This is becoming a real issue for me.
|
|
|
|
|
So, I've set my application up to resize the drawing when the window is resized by the user so that it keeps the same ratio of object to window size etc... Not sure if that's clear or not but I'll continue anyway. When I print, it prints fine when the window is maximized and everything in the window is in it's natural position in the maximized window. If the window is smaller, thus setting the drawing to be smaller so that it fits in the new window size, the print out is smaller as well. Only stands to reason, right? Well, I'm trying to figure out a way to print and always print as if the window was maximized regardless of the window's size. Any ideas?
|
|
|
|
|
Yeah, I'm using CView::OnPrint() but I don't understand the printing process enough to understand what the code is trying to do. I don't know how to modify it to, basically, zoom in on the CView client area to get the printout to look right.
|
|
|
|
|
The GetClientRect(...) method always returns the size of the client area on the screen, even when printing. You need to use something like the CPrintInfo::m_rectDraw when drawing to the printer. You can save the print rect in CView::OnBeginPrinting(...) and use the pDC->IsPrinting() to flag using the printer rect vs. the client rect.
This opens up a whole can of worms when trying to use your dynamic screen drawing code to draw to the more static printer page. There are other ways to get the printer page information. Search the MSDN for "get default print info" and see what you get. Of course this all opens a bigger can of worms.
You may want to just try using CPrintInfo::m_rectDraw first. It may be all you need.
Good Luck
Jonathan Craig
www.mcw-tech.com
|
|
|
|
|
Hi !
I wrote system hook for right mouse click i.e. using WH_MOUSE in SetWindowHookEx()
Now for the hook procedure in the .dll file I added the code..
//=====================================================
EXPORT LRESULT CALLBACK MouseProc(int nCode,WPARAM wParam,LPARAM lParam)
{
switch(wParam)
{
case WM_RBUTTONUP:
{
DisplayDialog();
return CallNextHookEx(hK,nCode,wParam,lParam);
}
default:
return CallNextHookEx(hK,nCode,wParam,lParam);
}
}
//======================================================
// The above code should display a Modless Dialog Box on screen .. when it intercepts a Right mouse click.
The problem I am facing here is that though the dialog box does pop up...instead of one ... they are multiple in number and keep on increasing !!!
I traced the whole execution and found that the hook procedure was receiving multiple WM_RBUTTONUP messages when I just right clicked once.
Why is this happening ?
Another thing.. What do I do if I wanted to check if the
Shift key was pressed when right click was made.
Do I have to install a Keyboard hook for this, or can I get the info from wParam itself.
Please Help
DB
Note:
1. DisplayDialog() function displays a dialog box on screen.
2. Variable hk stores the hook handle from SetWindowsHookEx function.
|
|
|
|
|
Is it possible to use RDS.Dataspace from Visual C++ to call a remote server with the http protocol. I can do this from VB, but I can't make it work from VC++.
Any comments ?
|
|
|
|
|
I am using WebBrowser control in VC++ project.
WebBrowser loads page form Intranet Server. I don't want to show message like "The page cannot be displayed" in case server is down. I want to show some local html page which will be stored on client computer.
Does anyone know how to catch event when page is not successfully loaded from server?
Thanks
Sanjeev.
|
|
|
|
|
You could try first testing the existence of the page programatically (just send a HEAD request - don't download the page). If the test succeeds, ask the web browser control to load the page. Otherwise, direct the control to a local 404 page.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
HANDLE SAHeap = HeapCreate( HEAP_GENERATE_EXCEPTIONS , 0 ,0 );
PSECURITY_ATTRIBUTES pSD = NULL;
ACL_SIZE_INFORMATION ASizeInfo;
DWORD LenNeeded , iAce;
BOOL DaclF , AclDefF;
BYTE DAcl [256];
BYTE AType;
PACCESS_ALLOWED_ACE pAce;
PACL pAcl = (PACL) &DAcl;
POSITION pos = filelist->GetHeadPosition();
for(short i = 0 ; i < filelist->GetCount() ; i++ )
{
GetFileSecurity( (LPCTSTR)filelist->GetNext(pos).GetString() , OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION
| DACL_SECURITY_INFORMATION , pSD , 0 , &LenNeeded );
pSD = (PSECURITY_ATTRIBUTES)HeapAlloc(SAHeap , HEAP_GENERATE_EXCEPTIONS , LenNeeded);
GetFileSecurity( (LPCTSTR)filelist->GetNext(pos).GetString() , OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION
| DACL_SECURITY_INFORMATION , pSD , LenNeeded , &LenNeeded );
GetSecurityDescriptorDacl(pSD , &DaclF , &pAcl , &AclDefF);
GetAclInformation(pAcl , &ASizeInfo , sizeof(ACL_SIZE_INFORMATION) , AclSizeInformation);
for(iAce = 0 ; iAce < ASizeInfo.AceCount ; iAce++)
{
AType = GetAce(pAcl , iAce , (LPVOID*)&pAce);
if(AType == ACCESS_ALLOWED_ACE_TYPE)
AfxMessageBox("Access");
}
}
The second time when first "for" loop run unhandled error happend after this line:
GetFileSecurity( (LPCTSTR)filelist->GetNext(pos).GetString() , OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION
| DACL_SECURITY_INFORMATION , pSD , 0 , &LenNeeded );
and thats access violation...error.
Any idea?
Mazy
"The more I search, the more my need
For you,
The more I bless, the more I bleed
For you."The Outlaw Torn-Metallica
|
|
|
|
|
If fileList has n positions, seems to me you're trying to obtain n+1 elements: one GetHeadPosition and n GetNext s. If the list has two elements, you'll run into an error at the second iteration.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
It seems that you are right.Now how can I deal with fileLlist ?
Mazy
"The more I search, the more my need
For you,
The more I bless, the more I bleed
For you."The Outlaw Torn-Metallica
|
|
|
|