|
|
I have a dll that multiple .exe's (and multiple instances of .exe's) link to. This dll performs some actions that require a temporary file.
Does anyone know if I call _tempnam from within a function of this dll, can I get back duplicate names? For example:
1. abc.exe calls dll function xxx(), and xxx() calls _tempnam(...).
2. before any file gets created with the name returned in (1), def.exe calls
xxx().
In this situation, could the same name be given by _tempnam in both (1) and (2)?
Thanks,
David
|
|
|
|
|
I guess there can be problems (to make sure, just call xxx twice from a test program).
In order to avoid this reace condition, you can use a global mutex just like this:
HANDLE mutex=CreateMutex(NULL,FALSE,"SOME_WEIRD_STRING_TO_MAKE_SURE_IT_IS_SYSTEM_WIDE_UNIQUE_LIKE_THIS__4FCCB370_D775_11D2_8FC5_0000F5140DA0_");
WaitForSingleObject(mutex,INFINITE);
xxx();
ReleaseMutex(mutex);
CloseHandle(mutex);
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
You know, some people actually read the documentation first? Others even read the CRT source coded that is provided with MSVC.
For the third category, I believe it has to be spelled out:
Yes, at the point you get a filename from _tempnam it's unique for the target directory.
|
|
|
|
|
Wow, aren't you just full of wisdom. Don't bother responding next time.
|
|
|
|
|
Dave_ wrote:
Wow, aren't you just full of wisdom. Don't bother responding next time.
YOU are giving ME sh*t for giving you a technically correct and complete answer?! You are indeed displaying your gratitude in a way suitable to anyone with the manors of a ringworm!
Displaying in public that you haven't read the documentation, and all other sources of information available, before asking the question, displays you are a lazy prick waiting to get stuff served on a silver plate.
You f***ed up! You need to be taught to try to find your own answers before bugging someone else. Either that, or you have proven you are just not suitable for this kind of occupation.
If I have been so kind to use my precious time to give you a technically correct answer, the least I expect is a little bit of gratitude. A plain "thanks" would have been enough. Hell, plain silence would have been enough. But noooo, the Great Kahuna of "Dave_" have to display that not only can't he read documentation and source code, he can also displays what an ungreatful bastard he is.
Good job, you have managed to make your point,
Have a nice day,
go play on the highway.
|
|
|
|
|
I want to add send mail facility in my application. For this purpose i want my application to use Outlook express and whenever it needs to send mail, it immediately use outlook express. Can you tell me how OR tell me about some example application. I would be more glad if the solution will be MFC free
|
|
|
|
|
1- ::ShellExecute("mailto:yourname@isp.com?subject=...&body=...",...)
2- If you need it automated and silent, see what's said about the MAPI32.DLL API in MSDN.
And I swallow a small raisin.
|
|
|
|
|
Simple MAPI is a very simple (as its name suggests) API for e-messaging. This API will use whenever messaging application that is registered as the "predetermined messaging application". If that happens to be the case in your target machines, then go search some Simple MAPI sample on the net (lots of them, for one without MFC dependencies, check Xiangyang Liu's article Sending and receiving e-mails from your program[^]).
To determine (non-programmatically) whether Outlook Express is the default messaging app, open it, go to Tools -> Options and look for a checkbox labeled "Outlook Express as predetemined Simple MAPI client".
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I am attempting to upgrade an application written for Windows 3.1 platform. It was originally developed using Borland C++ 4.5 and TurboPower Software's Data Entry Workshop 2.0. I am unfamilar with programming applications for Win 3.1 as I started learning on Win95. If all of the source code is available, is there a simple process of migrating it over to run on Win95/98/2000? Thanks in advance.
Rich
|
|
|
|
|
I'm afraid you have no other choice but to do it manually. The process ranges from moderately simple to almost impossible, depending on the complexity of the program and the libraries it depends on. In your case, I guess the TurboPower library will pose the most difficulties. MSDN provides very good porting tips in the article Porting 16-Bit Code to 32-Bit Windows[^].
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thank you for the response. I found the article Porting 16-Bit Code to 32-Bit Windows. Does anyone have any information on TurboPower library?
Rich
|
|
|
|
|
You could look at www.turbopower.com/products/orpheus
This may be the newer version of the old Win3.1 stuff - if so, and the calls etc are identical, it might ease the pain !!
Garth
|
|
|
|
|
I have an IDirectDrawSurface and I would like to save it as a bitmap. Im only interested in 24/32 formats. I have written some code, and it exports the file correctly. It locks the surface to get the bits, and then dumps it to a file. When I view the file with MS paint, it looks fine. However, when I open in Adobe Photoshop, the colors are off (I think the blue and red are switched). It seems odd to work in MSpaint but then not in photoshop. If anybody has experience doing this, please take a look at my code. Thanks
STDMETHODIMP CCaptureWindow::SaveScreenshot(LPTSTR pFile)
{
if (!g_pCapture || !g_pBaseFilter)
return E_UNEXPECTED;
CComPtr<IDDrawExclModeVideo> ddemv;
HRESULT hr;
if (FAILED(g_pCapture->FindInterface(&PIN_CATEGORY_PREVIEW,
&MEDIATYPE_Interleaved, g_pBaseFilter,
IID_IDDrawExclModeVideo, (void**)&ddemv)))
{
if (FAILED(hr = g_pCapture->FindInterface(&PIN_CATEGORY_PREVIEW,
&MEDIATYPE_Video, g_pBaseFilter,
IID_IDDrawExclModeVideo, (void**)&ddemv)))
{
return hr;
}
}
CComPtr<IDirectDrawSurface> pSurface;
CComPtr<IDirectDrawSurface7> pSurface7;
BOOL bExternal;
if (FAILED(hr=ddemv->GetDDrawSurface(&pSurface,&bExternal)))
return hr;
if (FAILED(hr=pSurface->QueryInterface(IID_IDirectDrawSurface7,(void**)&pSurface7)))
return hr;
DDSURFACEDESC2 desc;
desc.dwSize = sizeof(desc);
if (FAILED(hr=pSurface7->Lock(NULL,&desc,DDLOCK_WAIT | DDLOCK_READONLY,0)))
return hr;
if ((desc.ddpfPixelFormat.dwRGBBitCount < 24) || !(desc.ddpfPixelFormat.dwFlags & DDPF_RGB) || (desc.ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXEDTO8))
{
pSurface7->Unlock(NULL);
return E_UNEXPECTED;
}
HANDLE hFile = CreateFile(pFile,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
if (hFile == INVALID_HANDLE_VALUE)
{
pSurface7->Unlock(NULL);
return GetLastError();
}
CFile file(hFile);
BITMAPFILEHEADER bfh;
BITMAPINFO bmi;
DWORD sizeImage;
bfh.bfType = MAKEWORD('B','M');
bfh.bfReserved1 = 0;
bfh.bfReserved2 = 0;
bfh.bfOffBits = sizeof(bmi.bmiHeader);
bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biXPelsPerMeter = 0;
bmi.bmiHeader.biYPelsPerMeter = 0;
bmi.bmiHeader.biClrUsed = 0;
bmi.bmiHeader.biClrImportant = 0;
bmi.bmiHeader.biWidth = desc.dwWidth;
bmi.bmiHeader.biHeight = desc.dwHeight;
if (desc.ddpfPixelFormat.dwRGBBitCount == 32)
{
DWORD lPitch = desc.dwWidth * 3;
if (lPitch & 3)
lPitch = (lPitch & ~3) + 4;
sizeImage = desc.dwHeight * lPitch;
LPBYTE pBitmapMem = (LPBYTE)CoTaskMemAlloc(sizeImage+4);
if (!pBitmapMem)
{
pSurface7->Unlock(NULL);
return E_OUTOFMEMORY;
}
LPBYTE pCurrentWriteMem = (LPBYTE)pBitmapMem;
LPBYTE pCurrentReadMem = (LPBYTE)((LPBYTE)desc.lpSurface+((desc.dwHeight-1)*desc.lPitch));
for (DWORD i=0;i<desc.dwHeight;++i)
{
LPBYTE curWLine = pCurrentWriteMem;
LPBYTE curRLine = pCurrentReadMem;
for (DWORD j=0;j<desc.dwWidth;++j)
{
pCurrentWriteMem[0] = pCurrentReadMem[0];
pCurrentWriteMem[1] = pCurrentReadMem[1];
pCurrentWriteMem[2] = pCurrentReadMem[2];
pCurrentWriteMem += 3;
pCurrentReadMem += 4;
}
pCurrentWriteMem = curWLine + lPitch;
pCurrentReadMem = curRLine - desc.lPitch;
}
bfh.bfSize = sizeof(bfh) + sizeof(bmi.bmiHeader) + sizeImage;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biSizeImage = sizeImage;
file.Write(&bfh,sizeof(bfh));
file.Write(&bmi,sizeof(bmi.bmiHeader));
file.Write(pBitmapMem,sizeImage);
CoTaskMemFree(pBitmapMem);
}
else
{
sizeImage = desc.dwHeight * desc.lPitch;
bfh.bfSize = sizeof(bfh) + sizeof(bmi.bmiHeader) + sizeImage;
bmi.bmiHeader.biBitCount = (WORD)desc.ddpfPixelFormat.dwRGBBitCount;
bmi.bmiHeader.biSizeImage = sizeImage;
file.Write(&bfh,sizeof(bfh));
file.Write(&bmi,sizeof(bmi.bmiHeader));
file.Write(desc.lpSurface,sizeImage);
}
file.Close();
pSurface7->Unlock(NULL);
return S_OK;
}
|
|
|
|
|
First of all, looks like 75% of your code here is useless, you don't need to copy the source surface byte by byte. DirectDraw exposes a DC. Once you've got it, you simply do a StretchBlit to a destination DC.
<pre>
// m_pDDSOffscreen3 is a DirectDraw surface
HDC MemDC, SurfDC;
HBITMAP hBmp,hDib;
DDSURFACEDESC ddsd;
LPBYTE destbuffer=NULL;
BITMAP bmp;
PBITMAPINFO pbmi;
WORD cClrBits;
LPVOID lpBits=NULL;
if (m_pDDSOffscreen3==NULL) return;
// Get the size of the surface...
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
m_pDDSOffscreen3->GetSurfaceDesc(&ddsd);
// Create the Memorybitmap now...
HRESULT hr = m_pDDSOffscreen3->GetDC(&SurfDC);
if (SUCCEEDED(hr))
{
// Create the Memorybitmap now...
MemDC = ::CreateCompatibleDC( NULL );
hBmp = ::CreateCompatibleBitmap( SurfDC, ddsd.dwWidth, ddsd.dwHeight );
::SelectObject( MemDC, hBmp );
::BitBlt( MemDC, 0, 0, ddsd.dwWidth, ddsd.dwHeight, SurfDC, 0, 0, SRCCOPY );
// Bitmapstruct init...
::GetObject( hBmp, sizeof(BITMAP), (LPSTR)&bmp ); cClrBits = (WORD) 24;
pbmi = (PBITMAPINFO) LocalAlloc(LPTR, sizeof(BITMAPINFOHEADER));
/* Initialize the fields in the BITMAPINFO structure. */
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmi->bmiHeader.biWidth = bmp.bmWidth;
pbmi->bmiHeader.biHeight = bmp.bmHeight;
pbmi->bmiHeader.biPlanes = bmp.bmPlanes;
pbmi->bmiHeader.biBitCount = 24;
if( cClrBits < 24 ) pbmi->bmiHeader.biClrUsed = 2^cClrBits;
pbmi->bmiHeader.biCompression = BI_RGB;
pbmi->bmiHeader.biSizeImage = (pbmi->bmiHeader.biWidth + 7) /8 *
pbmi->bmiHeader.biHeight * 24;
pbmi->bmiHeader.biClrImportant = 0;
hDib = ::CreateDIBSection(NULL,pbmi,DIB_RGB_COLORS,&lpBits,NULL,0);
if (hDib==NULL) TRACE("CreateDIBSection failed\n");
// Get the bits from the DC to save it to disk...
GetDIBits( SurfDC, hBmp, 0, (WORD) bmp.bmHeight, lpBits, pbmi, 0 );
if( lpBits == NULL ) TRACE( "No memory for screenshot!\n" );
if (bAddTail)
{
CString name=_T("");
if (GetDocument()->addShot(name,nStart,nEnd) &&
pThumb->AddItem(CBitmap::FromHandle(hDib), name))
{
GetDocument()->addShotInfo(nStart,nEnd,
pThumb->GetImageListIndex(),pThumb->GetItemIndex());
}
}
else
{
// remplace
replaceShot(CBitmap::FromHandle(hDib));
}
m_pDDSOffscreen3->ReleaseDC(SurfDC );
::SelectObject(MemDC,NULL);
::DeleteDC(MemDC);
::DeleteObject(hBmp);
::DeleteObject(hDib);
</pre>
<hr noshade>
<font size="-1" face="arial"><i>And I swallow a small raisin.</i></font>
<b style="background-image:'url(http://www.arstdesign.com/hands.jpg)';width:50px;height:45px"></b>
|
|
|
|
|
Thanks for the tip, but I think your solution seems slightly wasteful. You suggest creating a DIB from a DDB which requires allocating a new DDB + memory for the DIB bits. Isn't Lock'ing the surface the same thing as getting the DIB bits (and hence you can avoid the DDB HBITMAP stuff)?
|
|
|
|
|
Todd Jeffreys wrote:
You suggest creating a DIB from a DDB
Yes? That is AFAIK what the very definition of a .BMP-file says it contains.
|
|
|
|
|
I created 8 buttons on a page and created OnClick calls the easy way by double clicking the buttons. After doing this I put break points in each one. Then when I ran the program the broke in the wrong one...they were all off by 1 and the last one did nothing.
This maybe part of the problem or just another one, but the resource.h file has duplicated numbers all over the place. I would think that they should all be unique.
All explainations welcomed!!!
Thanks
|
|
|
|
|
what do you mean?
but the resource.h file has duplicated numbers all over the place. I would think that they should all be unique.<br />
|
|
|
|
|
I ended deleting all the buttons and then adding them back in and now they work.
I still have dublicate numbers...maybe they are on a window by window basis.
|
|
|
|
|
I still have dublicate numbers...maybe they are on a window by window basis.
what numbers.. of what???
|
|
|
|
|
resource.h example:
#define IDC_RADIO7 1017
#define IDC_CHECK8 1017
#define IDC_ACTV_7 1017
#define IDC_MALF08 1017
#define IDC_MALF08_SYS1 1017
#define IDC_SYS8_FAU 1017
#define IDC_SYS1_MODE_SEL_SWITCH4 1017
#define IDC_MF_FRONT1 1017
#define IDC_ALQ122_DUP 1017
#define IDC_MF1_FRONT 1017
|
|
|
|
|
Its a common problem.
Theres a tool at http://www.codeproject.com/macro/resorg.asp that can help you reorganise.
Asim Hussain
e: asim@jawache.net
w: www.jawache.net
|
|
|
|
|
Has anyone found a workaround for disabling the arrow on an owner drawn menu when the popup menu item is disabled?
|
|
|
|
|
If you mean whether all the items to the left of the => arrow are disabled so you'd like to remove the menu item?
Can't you catch the OnInitMenu handler ( Or whatever it is in CMainFrame ) and call pMenu->ModifyMenu etc... to remove the arrow or just remove that menu item all together.
Asim Hussain
e: asim@jawache.net
w: www.jawache.net
|
|
|
|
|