|
|
Hi,
I am declaring a std::vector<double> vX. I am filling it up using vX.push_back(aNum).
The problem is i want to put the contents of vX into DP which is defined as
double DP[];
This is because an external routine requires an array that is of the form above.
Any ideas would be appreciated.
Thanks
Kash
|
|
|
|
|
Hi Kash,
IIRC, vector is guaranteed to be continuous (its the only container with the guarantee). So you should be able to return the address of element 0 - &vX[0].
Is vX declared as follows?
std::vector<double> vX;
Please correct me if I am wrong.
Jeff
|
|
|
|
|
I'm new to .Net and am going through a chapter in a book I just bought with an example of an e-mail validation string using a regular expression. The string doesn't work! Does anyone have a proper regex for validating e-mails?
If it's broken, I probably did it
bdiamond
|
|
|
|
|
bdiamond wrote:
The string doesn't work!
Meaning what? It allows an invalid address to pass, or it fails on a valid address?
Here are some examples of e-mail expressions:
http://www.breakingpar.com/bkp/home.nsf/Doc?OpenNavigator&U=87256B280015193F87256C40004CC8C6
http://www.regular-expressions.info/
http://www.codetoad.com/asp_email_reg_exp.asp
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
it allows an invalid e-mail address to pass.
here's the function:
bool CdotnetDlg::ValidEmail(CString strMail)
{
#pragma push_macro("new")
#undef new
CString strPattern = "[\\w]+@[\\w]+.[\\w]{2,3}";
Match* pMatch =Regex::Match(strMail,strPattern);
#pragma pop_macro("new")
return pMatch->Success;
}
If it's broken, I probably did it
bdiamond
|
|
|
|
|
Hey all, I have a .h and .lib for an API I would like to use. The only problem is, I need to use it from managed code, therefore, I need to turn it into a dll so I can use DllImport to import the functions. The API was written in C++. What is a quick and easy way to compile this into a dll that I can use?
|
|
|
|
|
what do u mean by "written in C++"?
give an example of a function you want to export.
Don't try it, just do it!
|
|
|
|
|
I want to draw a transparent sprite onto a HDC / HBITMAP from an array.
This is a simplified version of what I have.
Basically I want to draw a sprite (Helicopter) that moves around the screen.
But I can't seem to draw the helicopter without a black block surrounding it.
This is my example sprite - It should draw a diagonal blue and green line.
int yVals[4] = {0, 1, 2, 3};
int xVals[4] = {0, 1, 2, 3};
int colourVals[4] = {0x0000FF00, 0x0000FF00, 0x000000FF, 0x000000FF};
My device handles are:
HDC hSpriteDC;
HDC hMemDC;
HDC hMaskDC;
and a couple others for the background
HBITMAP hSpriteBitmap;
HBITMAP hMemBitmap;
HBITMAP hMaskBitmap;
I call this proc on start up. It creates the HDC's and HBITMAPS. It also draws only the
points that I want to see. I was hoping that it would leave the rest of the "drawing area" transparent. But it didn't.
void initHDC(HDC hDC)
{
hMaskDC = CreateCompatibleDC(hDC);
hMaskBitmap = CreateBitmap(4, 4, 1, 1, NULL);
hSpriteDC = CreateCompatibleDC(hDC);
hSpriteBitmap = CreateCompatibleBitmap(hDC, 4, 4);
hMemDC = CreateCompatibleDC(hDC);
hMemBitmap = CreateCompatibleBitmap(hDC, 4, 4);
SelectObject(hSpriteDC, hSpriteBitmap);
SelectObject(hMemDC, hMemBitmap);
SelectObject(hMaskDC, hMaskBitmap);
int i;
for(i = 0; i < 4; i++)
{
SetPixel(hSpriteDC, xVals[i], yVals[i], COLORREF(colourVals[i]));
SetPixel(hMaskDC, xVals[i], yVals[i], COLORREF(0x00FFFFFF));
}
}
I've also tried inserting
SetBkMode(hSpriteDC, TRANSPARENT)
into my code after the SelectObjects.
I call this Procedure from my OnPaint procedure:
I've tried all sorts of raster operations.
void drawSprite(int x, int y, int dx, int dy)
{
BitBlt(hMemDC, x - 40, y - 40, x + 40, y + 40, hHeliDDC, 0, 0, SRCCOPY);
//I also tried this:
//BitBlt(hMemDC, x - 40, y - 40, x + 40, y + 40, hSpriteDC, 0, 0, SRCCOPY);
//BitBlt(hMemDC, x - 40, y - 40, x + 40, y + 40, hMaskDC, 0, 0, SRCAND);
}
In my OnPaint() procedure, I have:
PAINTSTRUCT ps;
RECT r;
r.top = 0;
r.bottom = 500;
r.left = 0;
r.right = 800;
ps.rcPaint = r;
BeginPaint( hwnd, &ps );
//Draw BackGround
//My background is stored in hBackDC
BitBlt( hMemDC,
ps.rcPaint.left,
ps.rcPaint.top,
ps.rcPaint.right,
ps.rcPaint.bottom,
hBackDC,ps.rcPaint.left,
ps.rcPaint.top,
SRCCOPY );
drawSprite(x, y, dx, dy);
BitBlt(ps.hdc,
ps.rcPaint.left,
ps.rcPaint.top,
ps.rcPaint.right,
ps.rcPaint.bottom,
hMemDC,
ps.rcPaint.left,
ps.rcPaint.top,
SRCCOPY );
EndPaint( hwnd, &ps );
I have tried Seting the pixels in my OnPaint() procedure, but thats too slow.
I hope I've made my problem clear.
Please - any suggestions would be awesome.
|
|
|
|
|
void FooButton::TransparentBlt
(HDC hdcDest,
int nXDest,
int nYDest,
int nWidth,
int nHeight,
HBITMAP hBitmap,
int nXSrc,
int nYSrc,
COLORREF colorTransparent,
HPALETTE hPal)
{
CDC dc, memDC, maskDC, tempDC;
dc.Attach( hdcDest );
maskDC.CreateCompatibleDC(&dc);
CBitmap maskBitmap;
CBitmap* pOldMemBmp = NULL;
CBitmap* pOldMaskBmp = NULL;
HBITMAP hOldTempBmp = NULL;
memDC.CreateCompatibleDC (&dc);
tempDC.CreateCompatibleDC (&dc);
CBitmap bmpImage;
bmpImage.CreateCompatibleBitmap (&dc, nWidth, nHeight);
pOldMemBmp = memDC.SelectObject (&bmpImage);
if (dc.GetDeviceCaps (RASTERCAPS) & RC_PALETTE && hPal) {
::SelectPalette( dc, hPal, FALSE );
dc.RealizePalette();
::SelectPalette( memDC, hPal, FALSE );
}
hOldTempBmp = (HBITMAP) ::SelectObject (tempDC.m_hDC, hBitmap);
memDC.BitBlt (0, 0, nWidth, nHeight, &tempDC, nXSrc, nYSrc, SRCCOPY);
maskBitmap.CreateBitmap (nWidth, nHeight, 1, 1, NULL);
pOldMaskBmp = maskDC.SelectObject (&maskBitmap);
memDC.SetBkColor (colorTransparent);
maskDC.BitBlt (0, 0, nWidth, nHeight, &memDC, 0, 0, SRCCOPY);
memDC.SetBkColor (RGB (0,0,0));
memDC.SetTextColor (RGB (255,255,255));
memDC.BitBlt (0, 0, nWidth, nHeight, &maskDC, 0, 0, SRCAND);
dc.SetBkColor (RGB (255,255,255));
dc.SetTextColor (RGB (0,0,0));
dc.BitBlt (nXDest, nYDest, nWidth, nHeight, &maskDC, 0, 0, SRCAND);
dc.BitBlt (nXDest, nYDest, nWidth, nHeight, &memDC, 0, 0, SRCPAINT);
if (hOldTempBmp)
::SelectObject (tempDC.m_hDC, hOldTempBmp);
if (pOldMaskBmp)
maskDC.SelectObject (pOldMaskBmp);
if (pOldMemBmp)
memDC.SelectObject (pOldMemBmp);
dc.Detach();
} /ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Code copied from CExBitmap.cpp (codeproject article CExBitmap)
CBitmap bmpMask;
if( !bmpMask.CreateBitmap(
bmSrc.bmWidth, bmSrc.bmHeight, 1, 1, NULL) )
{
return FALSE;
}
CBitmap bmpTemp;
if( !bmpTemp.CreateCompatibleBitmap(
pdcDest, bmSrc.bmWidth, bmSrc.bmHeight) )
{
return FALSE;
}
CWorkDC dcTemp(pdcDest, &bmpTemp);
CWorkDC dcMask(pdcDest, &bmpMask);
if( dcTemp.BitBlt(0, 0, bmSrc.bmWidth, bmSrc.bmHeight,
pdcDest, xDest, yDest, SRCCOPY) )
{
dcSrc.SetBkColor(crTrans);
dcMask.BitBlt(0, 0, bmSrc.bmWidth, bmSrc.bmHeight,
&dcSrc, 0,0, SRCCOPY);
dcTemp.BitBlt(0, 0, bmSrc.bmWidth, bmSrc.bmHeight,
&dcSrc, 0, 0, SRCINVERT);
dcTemp.BitBlt(0, 0, bmSrc.bmWidth, bmSrc.bmHeight,
&dcMask, 0, 0, SRCAND);
dcTemp.BitBlt(0, 0, bmSrc.bmWidth, bmSrc.bmHeight,
&dcSrc, 0, 0, SRCINVERT);
pdcDest->BitBlt(xDest, yDest, nWidth, hHeight,
&dcTemp, 0, 0, SRCCOPY);
}
I hope this helps!
INTP
|
|
|
|
|
Is it possible to display a CFormView in a CFrameWnd without using all of the dyncreate stuff? I ask because I don't want to use any of the document stuff - I just want the CFrameWnd to display the CFormView in its client area.
Thanks,
Adam
|
|
|
|
|
Hi,
I am calling the following bit of code from a worker thread via SendMessage to update the user interface in the view:
LRESULT CNetworkMonitoringListView::OnThreadUpdate(WPARAM wParam, LPARAM lParam)
{
CString sResult;
LV_ITEM lvi;
lvi.mask = LVIF_TEXT | LVIF_DI_SETITEM;
lvi.iItem = (INT)lParam;
lvi.iSubItem = 0;
lvi.pszText = (LPTSTR)(LPCTSTR)lParam;
GetListCtrl().InsertItem(&lvi);
for (int i = 0; i < 5; i++)
{
lvi.iSubItem = i;
GetDocument()->m_cs.Lock();
sResult = GetDocument()->m_capturedPacket.GetDescription((UINT)lParam, i);
GetDocument()->m_cs.Unlock();
lvi.pszText = (LPTSTR)(LPCTSTR)(sResult);
GetListCtrl().SetItem(&lvi);
}
return 0;
}
The second time the message from the worker thread is processed
GetListCtrl().InsertItem(&lvi)
causes an access violation and fails to add another entry into the CListview, is there anything I can do?
Cheers
Packetlos
|
|
|
|
|
packetlos wrote:
I am calling the following bit of code from a worker thread via SendMessage to update the user interface in the view:
Use PostMessage() instead. Read this article.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Cheers for the link, i have read the article and I am doing what it suggests by using a user defined message to trigger OnThreadUpdate now using PostMessage() and it is still causing access violations. Any other things I should be looking at anybody?
Thanks
|
|
|
|
|
The VC Debugger will point you towards the location of the access violation, which should help you to fix the cause.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
// My Code
TCHAR m_szDrive[10];
TCHAR m_szDir[MAX_PATH];
TCHAR m_szFullPath[MAX_PATH];
CString sFile;
// Application Path
::GetModuleFileName(NULL,m_szFullPath,MAX_PATH);
_splitpath(m_szFullPath,m_szDrive,m_szDir,NULL,NULL);
sFile=m_szDrive;
sFile+=m_szDir;
sFile+=_T("myfile.txt");
HANDLE hfile=CreateFile(sFile,.... THAT DOESN'T WORK
Do you know how can I convert my string to the right parameter?
Try it, hfile always 0xfffffff
Thanks
Doc
|
|
|
|
|
doctorpi wrote:
HANDLE hfile=CreateFile(sFile,.... THAT DOESN'T WORK
Define "DOESN'T WORK" further. Are you getting compiler, or runtime errors? What does GetLastError() return?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Recommend using makepath(), it should work anyway. But the problem probably lies in the arguments to CreateFile() which you are not giving us. Does the file already exist? Are you opening is with CREATE_ALWAYS or what?
INTP
|
|
|
|
|
Hello doctorpi,
Here's a snippet that I used - it is part of code to examine a DACL and/or SACL.
Jeff
DWORD dwDesiredAccess = READ_CONTROL;
if( TRUE == m_bSACL ) { dwDesiredAccess |= ACCESS_SYSTEM_SECURITY; }
if( TRUE == bDirectory ) {
hFile = CreateFile( pszFileObject, dwDesiredAccess, 0,
NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
} else {
hFile = CreateFile( pszFileObject, dwDesiredAccess, 0,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
}
if( hFile == INVALID_HANDLE_VALUE ) {
outfile.WriteString( (CString)pszFileObject + _T("\n") );
switch( GetLastError() ) {
case ERROR_FILE_NOT_FOUND:
outfile.WriteString( _T(" ERROR: The system cannot find the file specified.\n") );
break;
case ERROR_ACCESS_DENIED:
outfile.WriteString( _T(" ERROR: Access Denied.\n") );
break;
case ERROR_BAD_NETPATH:
outfile.WriteString( _T(" ERROR: The network path was not found.\n") );
break;
case ERROR_SHARING_VIOLATION:
outfile.WriteString( _T(" ERROR: The process cannot access the file because it is being used by another process.\n") );
break;
case ERROR_PRIVILEGE_NOT_HELD:
outfile.WriteString( _T(" ERROR: A required privilege is not held by the client.\n") );
break;
default:
szMessage.Format( _T(" ERROR: %d\n"), GetLastError() );
outfile.WriteString( szMessage );
}
outfile.WriteString( _T("\n") );
return;
}
|
|
|
|
|
There could be lots of reasons for your code's not working fine. Use GetLastError() to find out.
Gurmeet S. Kochar
If you believe in God, it's because of the Devil
|
|
|
|
|
The error is that if I put
HANDLE hfile=CreateFile("c:\\Myapp\\Myfile.txt",......) WORKS (the handle is not -1) And if I put the code of my first post with the same name file when debugging the return value is -1 and the problem is related to the name of the file.
Why is diferent "c:\\Myapp\\Myfile.txt" to "c:\Myapp\Myfile.txt" that is what I receive from the get app path?
Thanks for your help.
Best Regards
Doc
|
|
|
|
|
So Sorry guys
Completely my fault. Unfortunately the file was open before, and the error was due to this.
Sorry for your time spent in this silly mistake.
Get a beer , I'll pay.
Doc
|
|
|
|
|
I've got a problem and I was wondering if anyone else has had it, and if so, how they fixed it.
I've created an installer package using Visual Studio, and it works just fine about 99% of the time. However, a few times when it goes to install the program (on an upgrade), it won't really upgrade the program to the new executable and create another entry in the add/remove programs window. I have the DetectNewerInstalledVersion set to true, along with Remove PreviousVersions, and have incremented the Version.
It does install/upgrade correctly most of the time, but on two computers so far, the user has to manaully uninstall the previous version before it will install correctly. Any ideas on what is going on/how to fix it?
|
|
|
|
|
Well not really a programming question. What, if any, kind of software protection scheme do you or you company use to protect yourself against piracy, ect?
Any recommendations for commercial products?
Artificial intelligence is no match for natural
stupidity.
|
|
|
|
|