|
Have fun[^]
(cross-posting is a bad habit.)
Back to real work : D-27.
|
|
|
|
|
Just a begginer question ...
If I want to use COM components in my application, do I have to do something in my application ? Do I have to activate something ?
As I understand it I simply would have to do something like ( very simplified ) : as explained in Michael Dunn article :
ISomeCOMComponent* pInterface;
...
CoInitialize ( NULL );
...
CoCreateInstance(..., (void**) &pInterface );
...
...
pInterface->Release();
...
CoUninitialize();
Thanks.
|
|
|
|
|
This code is fine. Of course, in order to work, the COM object must be properly registered, otherwise CoCreateInstance will miserably fail.
(as long as your app is single-threaded, it's ok. But you may encounter issues with CoInitialize(NULL) on a per thread basis if your app is multi-threaded).
Back to real work : D-27.
|
|
|
|
|
Maximilien wrote:
Do I have to activate something ?
Yes, but you already do that with CoInitialize() and CoUninitialize()
So your code should work just fine
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Hi.
C++ offers the new operator to allocate a section of memory via heap.
C offers the general malloc set of functions to allocate a section of memory via heap.
Windows offers a series of functions. I would like to know what is the best memory allocation tool to use under windows. Again, I am a C++ programmer.
I believe Windows has these memory related functions.
GlobalAlloc()
GlobaFree()
HeapAlloc()
HeapFree()
LocalAlloc()
LocalFree ()
I would like to like under a C++ Windows program, what are the most appropriate memory allocation tool to use? Currently, I use C++ new operator to develop Windows winsock programs. However, I see programmers use GlobalAlloc almost all the time for Windows and Windows network programs. What is the advantage, if any, of GlobalAlloc that C++ new lacks, if any?
Thanks,
Kuphryn
|
|
|
|
|
Well, for all intensive purposes, Global/Local/HeapAlloc/Free() amount to the same thing, since windows doesn't provide a separate local and global heap. As the SDK documentation states, you should probably avoid using the "Local/Global" functions to allocate heap memory, because they are slower and don't provide as many features, and use the Heap* functions instead, but you need to review the documentation to see what fits best for a particular need.
HeapAlloc*ated memory isn't movable. GlobalAlloc*ated memory is guaranteed to be aligned on an 8-byte boundary, and are still used a lot in DDE, clipboard and OLE data objects.
There is also Virtual* functions as well.
Here's something that may help in comparing them (from MSDN):
- The following functions are equivalent: GlobalAlloc, LocalAlloc, and HeapAlloc with the handle returned by the GetProcessHeap function.
- The VirtualAlloc function allows you to specify additional options for memory allocation. However, its allocations use a page granularity, so using VirtualAlloc can result in higher memory usage.
- The malloc function has the disadvantage of being run-time dependent. The new operator has the disadvantage of being compiler dependent and language dependent.
- The CoTaskMemAlloc function has the advantage of working well in either C, C++, or Visual Basic. It is also the only way to share memory in a COM-based application, since MIDL uses CoTaskMemAlloc and CoTaskMemFree to marshal memory.
Of course, in C++, you'd use new so you can call constructors, which is a good thing But for struct ures (that don't do C++ things, since structs are completely public classes in C++), the Win32 Memory Management functions are quite useful.
|
|
|
|
|
|
|
Hi all,
I have a function (see following function), takes a structure of file information and file name. It prints the file with appropriate exe file according to their extention.
file information structure contains: file name, file type, file date, file size...etc.
I dont' get any problem printing the first file but crash for second file to print..
Is it because of the way I defined ShellExecuteInfo???
If so, what is the problem and how to fix it???
Thank you.
<br />
int myfunction(FileInfo afile, CString fileName)<br />
{<br />
int wordfile=0;<br />
CString msg;<br />
CString filetype = afile->type;<br />
<br />
int found =0;<br />
<br />
SHELLEXECUTEINFO lpExecInfo;<br />
lpExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); <br />
lpExecInfo.lpVerb = "open";
lpExecInfo.lpDirectory = NULL; <br />
lpExecInfo.nShow = SW_SHOW ;
lpExecInfo.hInstApp = (HINSTANCE) SE_ERR_DDEFAIL ;
<br />
if(filetype.CompareNoCase(".xls") == 0 || filetype.CompareNoCase(".csv") == 0 || filetype.CompareNoCase(".csv") == 0|| filetype.CompareNoCase(".wks") == 0 || filetype.CompareNoCase(".zip")==0)<br />
{ <br />
<br />
else if(filetype.CompareNoCase(".xls") == 0 || filetype.CompareNoCase(".csv") == 0|| filetype.CompareNoCase(".wks") == 0)<br />
{<br />
found = 1; <br />
AfxMessageBox(" EXCEL FILE FOUND !!!\n\tPrint it manually"); <br />
lpExecInfo.lpFile = "j:\\smp\\smp\\printExcel\\debug\\printexcel.exe";
lpExecInfo.lpParameters = fileName;
msg.Empty();<br />
msg = "Printing " + fileName + " completed.\n Press OK to continue...";<br />
<br />
<br />
}
<br />
else if(filetype.CompareNoCase(".doc")== 0 || filetype.CompareNoCase(".rtf")==0 || filetype.CompareNoCase(".htm") == 0 || filetype.CompareNoCase(".html")==0)<br />
{<br />
wordfile = 1;<br />
found = 1; <br />
lpExecInfo.lpFile = "j:\\smp\\smp\\wordprinting\\debug\\wordprinting.exe";
lpExecInfo.lpParameters = fileName;
<br />
}
<br />
else if(filetype.CompareNoCase(".msg")==0)<br />
{<br />
lpExecInfo.lpFile = fileName;
<br />
}
<br />
ShellExecuteEx(&lpExecInfo); <font color="red">here where I got error for second file.</font><br />
<br />
if(lpExecInfo.hProcess !=NULL)<br />
{<br />
::WaitForSingleObject(lpExecInfo.hProcess, INFINITE);<br />
::CloseHandle(lpExecInfo.hProcess);<br />
} <br />
if(wordfile != 1)<br />
MessageBox(msg);<br />
<br />
}
return found;<br />
}<br />
|
|
|
|
|
You didn't say what the error is, but I see two problems. First, the fMask member of the struct is not initialized, so it has garbage in it. It's always a good idea to zero-init structs. Second, for the hProcess member to be filled in, fMask must include SEE_MASK_NOCLOSEPROCESS.
--Mike--
"I'd rather you just give me a fish today, because even if you teach me how to fish, I won't do it. I'm lazy." -- Nish
Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
yes.. you were right.. i missed that..
the error was just crash.. you know general protection error.
Thanks.
|
|
|
|
|
Howdy,
I have a SDI (chat) app, in my CView I create 2 Rich Edit windows one fills 80%(top of CView receive text) and the other fills the last 20% (bottom Send text) they are both classes derived from CRichEditCtrl.
For some reason these 2 controls are not receiving my SendMessage commands from CView on 9x machines. (The sendmessage commands work fine on Windows 2k.) I have looked up the messages on MSDN and they should work on any 9x platform and nt 3.51 and up with RichEdit 1.0, the messages are:
EM_SCROLLCARET
EM_EXSETSEL
EM_GETEVENTMASK
Plus my Context Menus containded in my derived RichEdit classes do not display on 9x machines.
I know this is probably vague but does anyone have any suggestions?
|
|
|
|
|
Use MSDEV Spy++ to figure out if messages are really processed or not.
Back to real work : D-27.
|
|
|
|
|
Hi,
I do not know why I can not control "Size" of the chars print out for most of the Default Printers (works only on Window XP)!
In Window XP if I change the follwing command ... then it changes the size ( 9 & 72), but for others ... nothing affected! Can someone help me to pin-point the problem?
<br />
lf.lfHeight = -MulDiv(9, dc.GetDeviceCaps(LOGPIXELSY), 72);<br />
Here is my whole codes:
<br />
CPrintDialog printDlg(FALSE, PD_RETURNDEFAULT | PD_RETURNDC);CHeaderCtrl *pHeader = m_saleReport.GetHeaderCtrl();<br />
<br />
int i;<br />
<br />
if (printDlg.DoModal() == IDCANCEL)
return;<br />
<br />
CDC dc;<br />
CPrintInfo Info;<br />
CFont oFont;<br />
<br />
dc.Attach(printDlg.GetPrinterDC());
dc.SaveDC();
dc.m_bPrinting = TRUE;<br />
<br />
CString strTitle;
<br />
DOCINFO di;
::ZeroMemory (&di, sizeof (DOCINFO));<br />
<br />
di.cbSize = sizeof (DOCINFO);<br />
di.lpszDocName = strTitle;<br />
<br />
BOOL bPrintingOK = dc.StartDoc(&di);
<br />
int ppiX = dc.GetDeviceCaps(LOGPIXELSX);<br />
int ppiY = dc.GetDeviceCaps(LOGPIXELSY);<br />
<br />
int x0,y0,x1,y1;<br />
x0 = ppiX * (8 - 5.5)/2;
y0 = ppiY;
x1 = dc.GetDeviceCaps(HORZRES);
y1 = dc.GetDeviceCaps(VERTRES);
<br />
Info.m_rectDraw.SetRect(x0,y0,x1+400,y1);
<br />
<br />
LOGFONT lf; <br />
memset(&lf, 0, sizeof(LOGFONT));
::ZeroMemory(&lf, sizeof(LOGFONT));<br />
<br />
lf.lfHeight = -MulDiv(9, dc.GetDeviceCaps(LOGPIXELSY), 72);<br />
strcpy(lf.lfFaceName, "Garamond");
<br />
oFont.CreateFontIndirect(&lf);
dc.SelectObject(&oFont);
<br />
CString text("A") ;<br />
CSize csText = dc.GetTextExtent(text) ;
<br />
int lines_per_page = (int)(Info.m_rectDraw.Height() / csText.cy) ;<br />
int lines_in_listbox = m_saleSummary.GetCount();<br />
int headercolumn = pHeader->GetItemCount();<br />
int line_printing = 0 ;<br />
<br />
HDITEM hdi;<br />
TCHAR lpBuffer[256];<br />
bool fFound = false;<br />
<br />
hdi.mask = HDI_TEXT;<br />
hdi.pszText = lpBuffer;<br />
hdi.cchTextMax = 256;<br />
<br />
Info.SetMaxPage((lines_in_listbox / lines_per_page) + 1);<br />
<br />
for (UINT page = Info.GetMinPage();<br />
page <= Info.GetMaxPage() && bPrintingOK; page++)<br />
{<br />
Info.m_nCurPage = page;<br />
dc.StartPage();
CString Text; <br />
Text = m_saleReport.GetItemText(i,j);
dc.DrawText(Text, CRect(x, y, x + Info.m_rectDraw.Width(), y + csText.cy), DT_EXPANDTABS);<br />
}<br />
<br />
dc.EndPage();<br />
dc.EndDoc(); <br />
dc.RestoreDC(-1);
dc.DeleteDC() ;
Many thanks
|
|
|
|
|
Hi guys,
I'm developing an app and having a complete nightmare trying to support Windows 98! It runs solid like a rock on Windows 2000 and Xp, but with 98 it just crashes in the oddest of places. One of these is inside the AlphaBlend() function, which is a new function included in the November 2001 Platform Sdk. It is supposed to work under 98 no problem.
The AlphaBlend() code crashes inside msimg32.dll, and I read somewhere that you must not package this dll with your product... I am currently not doing this, but wonder if perhaps I should anyway ?
Besides saying that Windows 98 licks the donkey's butt, does anyone have any ideas what could be going wrong? I'm debating just adding fine print saying something like "Run on Windows 98 at your own risk"
swinefeaster
Check out Aephid Photokeeper, the powerful digital
photo album solution at www.aephid.com.
|
|
|
|
|
Swinefeaster wrote:
One of these is inside the AlphaBlend() function, which is a new function included in the November 2001 Platform Sdk. It is supposed to work under 98 no problem.
No, to get it compiled fine, you probably use WINNT_VER=0x0500 or something like that. Doing so, you link with a W2K+ vtable from any dll. That's probably why it fails miserably on 9X systems.
That's certainly bad, but I believe you must have two separate builds.
Back to real work : D-27.
|
|
|
|
|
Well it does compile fine. It just doesn't run fine!
But nevertheless, I tried defining _WIN32_WINNT 0x0500 in StdAfx.h, and rebuilt the whole thing, and now it even crashes in the toolbar classes and all sorts of other places
What do you mean by a vtable? Isn't a vtable the virtual lookup table used in virtual functions? Or am I missing something?
Also, it doesn't make sense to have multiple builds... I mean all the other software out there has a single install for 98/Me/2000/Xp ???
Thanks!
swine
Check out Aephid Photokeeper, the powerful digital
photo album solution at www.aephid.com.
|
|
|
|
|
Swinefeaster wrote:
Well it does compile fine. It just doesn't run fine!
I know.
Swinefeaster wrote:
Also, it doesn't make sense to have multiple builds... I mean all the other software out there has a single install for 98/Me/2000/Xp ???
May be. You could end up with a proxy dll that will, depending on the OS on which it's running, will load one of two child dlls : one for systems that don't support alpha-blending, one for those which do.
Back to real work : D-27.
|
|
|
|
|
I downloaded this sample from MSDN about enumerating processes under Win9x. It uses Psapi.dll (so includes Psapi.h) to access functions used to retrieve all running processes, here is the code:
#include <<windows.h>>
#include <<stdio.h>>
#include <<psapi.h>>
void PrintProcessNameAndID( DWORD processID )
{
char szProcessName[MAX_PATH] = "unknown";
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
if (NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName) );
}
else return;
}
else return;
printf( "%s (Process ID: %u)\n", szProcessName, processID );
CloseHandle( hProcess );
}
void main( )
{
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
return;
cProcesses = cbNeeded / sizeof(DWORD);
for ( i = 0; i < cProcesses; i++ )
PrintProcessNameAndID( aProcesses[i] );
}
Now when i try to compile this is compiles fine, but when it runs it gives me the error: "The PSAPI.DLL file is lonked to missing export NTDLL.DLL:NtAllocateVirtualMemory"
Now i did a search for NTDLL.DLL and it is in my windows system directory, so i opened it up with Dependency viewer and it could not find a function NtAllocateVirtualMemory.
Now what is wrong here? do i have a wrong DLL?? Even if i did, there is another question i asked myself. You see i opened up Taskmon.exe in Dependency viewer and it just uses the standard libraries like GDI.DLL, USER32.DLL, etc...
So it has to be possible to enumerate processes without the PSAPI so you can avoid the DLL problem. I wouldn't know how though...
If anyone has any ideas, please share them, any help is appreciated.
Thanks
Kuniva
--------------------------------------------
|
|
|
|
|
I have this exported function in NTDLL.DLL. And am running W2K SP2.
Back to real work : D-27.
|
|
|
|
|
I forgot to tell you, PSAPI.dll is not for W9X systems. It's too bad you got the sample from MSDN and you didn't get the sample in full length.
On W9X, you use CreateToolhelp32Snapshot and an enumerator. Searching MSDN with PSAPI as keyword brought me the full length sample in rank 1 ! And you have to switch case all possible OSes.
Back to real work : D-27.
|
|
|
|
|
I have a rather large dialog application that really needs a line drawn to divide it into two sections. Its a serial communcations dialog and the top part handles sending out data (32 user filled edits) while the bottom section is responsible for displaying incoming messages ( 14 read-only edits). I have no problem with the Tx/Rx aspects but I would really like to draw a line between the two. I have no experience whatsoever in this area and am looking for an answer that is detailed enough that I can insert it into my code. I created the dialog using the VS 6 project wizard if that matters. From the small amount of reading I've done (looking in CPaintDC and related items in the MSDN library) I didn't get to far. I am sure I can figure this out if I take the time to go through it in detail but I would really appreciate it if someone would just give me a either a walk through or the code I need. If more info is required just ask... I will provide whatever is needed
---------------------------------------------
The greenest grass is NOT on the other side of the fence, its the grass you take care of. Have you watered your lawn lately?
- Just remember when you point a finger at someone else, you are only one finger away from making a fist to hit them with!
|
|
|
|
|
Forget CPaintDC, add a groupbox and make it as thin as 1 pixel height.
If you can't, because you use grid locking and stuff, just go the hardcore way : open the .rc file and set the 1 there.
Back to real work : D-27.
|
|
|
|
|
As far as I know, I haven't set any grid locking. But I haven't ever delved into this aspect and if you could some code I could either paste or use as a guideline I would truly appreciate it
---------------------------------------------
<i>The greenest grass is NOT on the other side of the fence, its the grass you take care of. Have you watered your lawn lately?</i>
<i> - Just remember when you point a finger at someone else, you are only one finger away from making a fist to hit them with!</i>
|
|
|
|
|
You didn't get it right;P. You just need your mouse! in the dialog editor. Insert a groupxbox control, and resize it.
Back to real work : D-27.
|
|
|
|
|