|
Dear Experts
Previously I could open a file by using following code snippet in Visual C++ 6 :
CString fileName = "c:\\1.bin";
fopen(fileName,"wb");
But now I switched to visual C++ 2005 and activate unicode character set, but above code does not work.
Please give a code snippet that I can use to feed a CString as a array of TCHAR to fopen function.
Thanks
Mahdi
|
|
|
|
|
Hello,
Since you set the property to Unicode Character Set, you can try like this.
CString fileName = L"c:\\1.bin";
CT2CA filen(fileName);
fopen(filen,"wb");
Hope this helps.
Regards,
A. Gopinath.
|
|
|
|
|
|
Use the TCHAR version of fopen . Then the code can be used with Unicode and MBCS builds:
CString fileName = _T("c:\\1.bin");
_tfopen(fileName, _T("wb"));
|
|
|
|
|
Thanks , it works perfect.
|
|
|
|
|
I write a custom symbol component like logomarker symbol ,but i use agg instead of gdi. When I open shape files in arcmap and use my custom symbol to render the data, It is successful. However , when I open geodatabase files,as the same as shape files, It will be fail. It render blank. When I load this data again. It will render with the default symbol correct. Why?
I use aggplus which is encapsulated like GDI+. the main code is follow(full code about main class in attachment):
Aggplus::Graphics *m_pGraphics;
STDMETHODIMP CCartoSymbolMarker::SetupDC(OLE_HANDLE hDC, ITransformation *Transformation)
{
m_ipTrans = Transformation;
m_pGraphics = Graphics::FromHDC((HDC)hDC);
return S_OK;
}
STDMETHODIMP CCartoSymbolMarker:raw(IGeometry *Geometry)
{
if (!Geometry)
return E_POINTER;
IPointPtr spPoint(Geometry);
if (spPoint == NULL)
return E_FAIL;
double x=0, y=0;
FromMapPoint((IDisplayTransformation*)m_ipTrans, spPoint, &x, &y);
Pen myPen(Color(255,0,0,255), 1);
m_pGraphics->DrawRectangle(&myPen, x, y, 10, 20);
return S_OK;
}
STDMETHODIMP CCartoSymbolMarker::ResetDC()
{
delete m_pGraphics;
m_pGraphics = NULL;
return S_OK;
}
Aggplus Graphics class:
Graphics *Graphics::FromHDC(HDC hdc) { return(new Graphics(hdc)); }
Graphics::Graphics(HDC hdc) : m_dwConfigFlags(0)
{
RECT clipBox;
::GetClipBox(hdc, &clipBox);
int nW=clipBox.right-clipBox.left;
int nH=clipBox.bottom-clipBox.top;
ASSERT(nW>0 && nH>0);
z_Create(nW, nH, -4*nW, NULL);
m_dwConfigFlags|=def_flag_G_FromHDC;
m_fromhdc_HDC=hdc;
m_fromhdc_X=clipBox.left;
m_fromhdc_Y=clipBox.top;
}
Graphics::~Graphics()
{
#ifdef def_AP_Update_Dc_at_End
if(m_dwConfigFlags & def_flag_G_FromHDC)
{
BITMAPINFO hDib;
memset(&hDib, 0, sizeof(BITMAPINFO));
hDib.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
hDib.bmiHeader.biWidth = m_dwWidth;
hDib.bmiHeader.biHeight = m_dwHeight;
hDib.bmiHeader.biPlanes = 1;
hDib.bmiHeader.biBitCount = 32;
hDib.bmiHeader.biCompression = BI_RGB;
hDib.bmiHeader.biSizeImage = m_dwWidth * m_dwHeight * 4;
#ifndef _X_NODCAlpha_
LPVOID pBits;
HBITMAP hBitmap = CreateDIBSection(m_fromhdc_HDC, &hDib, DIB_RGB_COLORS, &pBits, NULL, 0);
if(!hBitmap) ASSERT(FALSE);
else
{
memcpy(pBits, buffer, m_dwWidth * m_dwHeight * 4);
HDC mdc=CreateCompatibleDC( m_fromhdc_HDC );
if(!mdc) ASSERT(FALSE);
else
{
HBITMAP hbmOld=(HBITMAP)::SelectObject(mdc, hBitmap);
BLENDFUNCTION bln;
bln.BlendOp=AC_SRC_OVER;
bln.BlendFlags=0;
bln.SourceConstantAlpha=255;
bln.AlphaFormat=AC_SRC_ALPHA;
AlphaBlend(m_fromhdc_HDC, m_fromhdc_X, m_fromhdc_Y, m_dwWidth, m_dwHeight, mdc, 0, 0, m_dwWidth, m_dwHeight, bln);
//BitBlt(m_fromhdc_HDC, m_fromhdc_X, m_fromhdc_Y, m_dwWidth, m_dwHeight, mdc, 0, 0, SRCCOPY);
::SelectObject(mdc, hbmOld);
//::GdiFlush();
DeleteDC(mdc);
}
:eleteObject(hBitmap);
}
#else
SetDIBitsToDevice(m_fromhdc_HDC, m_fromhdc_X, m_fromhdc_Y, m_dwWidth, m_dwHeight,
0, 0, 0, m_dwHeight,
buffer, &hDib, DIB_RGB_COLORS);
#endif //_X_NODCAlpha_
}
#endif //def_AP_Update_Dc_at_End
delete(m_agg_pREN);
delete(m_agg_ppixf);
if(!(m_dwConfigFlags&def_flag_G_ExtBuffer))
{
delete(buffer);
}
}
|
|
|
|
|
I am getting assertion in the first line of this function. ( part of wxdebug in BaseClasess lib of DirectShow 8.1) Fine, but the comment does not really say if it is bad to have a mixture of retail / debug library. Of course execution stops.
Interestingly - what is the "double negative" for anyway?
I guess basic C ! and ^ precedence "trick"?
/* Each time we create an object derived from CBaseObject the constructor will
call us to register the creation of the new object. We are passed a string
description which we store away. We return a cookie that the constructor
uses to identify the object when it is destroyed later on. We update the
total number of active objects in the DLL mainly for debugging purposes */
DWORD WINAPI DbgRegisterObjectCreation(const CHAR *szObjectName,
const WCHAR *wszObjectName) {
/* If this fires you have a mixed DEBUG/RETAIL build */
ASSERT(!!szObjectName ^ !!wszObjectName);
/* Create a place holder for this object description */
ObjectDesc *pObject = new ObjectDesc;
ASSERT(pObject);
|
|
|
|
|
The double !! is negating twice that does nothing with bool expressions but converts non-bool expressions to bool. !!szObjectName is basically the equivalent of (bool)szObjectName. Some people like !! more than (bool) because !! doesn't give "low performance because of conversion to bool" warnings with any compilers as far as I know and of course it is easier to type in than (bool). The assert expression in your case is true when exactly one of the parameters is NULL while the other is non-NULL. If both parameters are NULL or none of them is NULL then the assert fires.
|
|
|
|
|
Hi,
Can anybody suggest me how can i convert a string from utf8 (like wchar_t toTranscode[] = L"ناعسالاخخ";) format to ascii (like äÇÚÓÇáÇÎÎ)..
I have tried with the following code ..but when i am trying to print char array pToFill it is blank.
#include "stdio.h"
#include <string.h>
#include "stdlib.h"
#define _CRT_SECURE_NO_WARNINGS
int main()
{
FILE *p = NULL;
size_t len = 0;
unsigned int convertedChars = 0;
int ret;
wchar_t toTranscode[] = L"ناعسالاخخ";
unsigned int wLent = wcslen((const wchar_t*)toTranscode);
int maxCharLen = 6*wLent;
wchar_t* pWideCharBuf;
char* pToFill;
unsigned int i;
pWideCharBuf = (wchar_t*)malloc(wLent+1);
pToFill = (char*)malloc(maxCharLen+1);
for (i = 0; i < wLent; ++i)
pWideCharBuf[i] = toTranscode[i];
pWideCharBuf[wLent] = 0x00;
memset (pToFill, 0, maxCharLen+1);
ret = wcstombs_s(&convertedChars, pToFill, maxCharLen, pWideCharBuf, maxCharLen);
printf("ret is %d\n", ret);
printf("the ascii char is = %s\n", pToFill);
printf("to test\n");
p = fopen("hello.txt", "w");
if (p== NULL) {
printf("Error in opening a file..");
}
len = strlen(pToFill);
fwrite(pToFill, len, 1, p);
fclose(p);
printf("\nWritten Successfuly in the file.\n");
return 0;
}
please help
|
|
|
|
|
I get error 0x2A (EILSEQ ) when trying to convert this string. According to MSDN[^] this means it has encountered a character that it cannot convert.
Use the best guess
|
|
|
|
|
Hi sir,
Can u please suggest me then how can i convert Arabic characters stored in utf-8 format in database to ascii characters in c.
Is there any built-in function through which i can perform conversion from utf-8 to ascii.
Thanks
|
|
|
|
|
Try the following:
_locale_t locale = _create_locale(LC_CTYPE, "Arabic");
errno_t ret = _wcstombs_s_l(&convertedChars, pToFill, maxCharLen, pWideCharBuf, maxCharLen, locale);
Use the best guess
|
|
|
|
|
Thank you so much sir
It solved my problem.
|
|
|
|
|
Hello Sir,
The solution which you have given is working fine for me in windows machine But now I need to implement the same thing (utf-8 to ascii conversion) in a POS terminal which neither has 'locale.h' nor _wcstombs_s_l in the stdlib.
The POS terminal has linux kernal.My quries are :
1)Instead of using the function _wcstombs_s_l and create_locale can I replace it with the function definition itself.
2)If I can then please if possible provide me the link where I can find the proper definition of these two functions.
3)If i can not then is there any other way to implement utf8 to ascii conversion.
Please help.
Thanks
|
|
|
|
|
|
You should be aware that all solutions involving wcstombs and related depend on the locale and the typical encoding might not be what you call 'ascii'.
Actually, what is called ASCII does not contain any Arabic characters whatsoever. Probably, you are referring to a specific codepage that uses ASCII + some Arabic characters?
In that case, it's probably a good idea to set the proper locale before conversion (see Richard MacCutchans post for info), so you get the correct codepage and not, as you probably get with the code given so far, UTF-8 encoding, which means that the text file will contain multiple bytes per character.
For instance, see http://stackoverflow.com/questions/2190190/wcstombs-character-encoding[^]. Probably something like setlocale( LC_ALL, "ar.1256" ); will do what you need; it should set the codepage to windows 1256 (which is used for arabic) and use the (generic) Arabic locale.
Locales and encoding are a quite complicated issue, so you should be careful and precise when using them. Also, by C++ definition the locale employ system-dependent strings for locale, so if should cater to the platform you are coding for.
|
|
|
|
|
Thanks Sir for your reply.
It solved my problem.
|
|
|
|
|
I want to implement T13 ATA Secure Erase and can not find any documentation. Is something available?
I found this http://cmrr.ucsd.edu/people/Hughes/SecureErase.shtml[^]
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
There are other factors to consider besides secure erasure.
Like data remanance, correctly implemented PC BIOS (ie. it hasn't been compromised), PCI cards with onboard BIOS etc. Plus there's the thorny issue of SSD data remanance.
If at all possible the HDD should be encrypted, but not so good with SSD.
harddisk_ata_security_v1.1-1.pdf
"It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan
That's what machines are for.
Got a problem?
Sleep on it.
|
|
|
|
|
Thanks for answering to my problem, but I have a simple task and I can`t find documentation on T13 Secure Erase
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
I had a look at the t13.org website and they allow you download documents if you register and login.
"It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan
That's what machines are for.
Got a problem?
Sleep on it.
|
|
|
|
|
Thanks again. I searched the site before. Actually I need something like an API or SDK.
VII. 36. When you surround an army, leave an outlet free. Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
|
Thanks a lot
VII. 36. When you surround an army, leave an outlet free. Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
David's pointing you to the spec is an excellent answer.
A few things I will add to the mix:
* You will need multiple commands ( SECURITY ERASE PREPARE, SECURITY ERASE UNIT, and possibly other SECURITY commands ) from the spec in order to accomplish a secure erase.
* Sending (single-sector) ATA passthru commands from uesr mode applications is possible on Windows (XP SP2 and newer, IIRC), assuming you have Admin privileges on the system. You will need do some Googling on IOCTL_ATA_PASSTHRU_DIRECT in order to find relevant information.
* That being said, you will still be at the mercy of the system BIOS and possibly the O/S. Once a SECURITY FREEZE LOCK is sent to the drive, it is *generally* difficult or impossible to send SECURITY ERASE to the drive. Some motherboard BIOSs send the SECURITY FREEZE LOCK prior to start of boot just to ensure a drive is not accidentally or maliciously erased.
All of this is from my memory, which is several years old at this point.
|
|
|
|
|