|
does this compile?
this doesn't seem right:
WCHAR *szTempLine = NULL;
the docs i see say getline takes a ref to a std::string as the string param, not a WCHAR ptr.
maybe:
wstring str;
getline(sqlDBFile, str, '\n');
?
|
|
|
|
|
I saw that too. I think there are 2 of them, 1 in string, and 1 in istream, and that the sample I found on c++ website was in mistake of it's use. I'm using fstream, and it does not exist in that header.
hmmmmmmmmmm
|
|
|
|
|
I got the getline to work, but I can't figure out how to advance to the next line.
And even if I can get to the next line, I can't figure out how to build the buffer with sql command text until I reach GO. Sure like that stringbuilder in asp.net.
The wifstream was suppose to return the unicode chars from the file, but I get ansi chars.
I'm close here, just need lots of refinement.
Any ideas are welcomed.
std::wifstream *sqlDBFile = new std::wifstream;
sqlDBFile->open(szFilePath);
if (sqlDBFile->is_open() ) {
while (sqlDBFile->good() ) {
WCHAR *pzSQLCommand = new WCHAR[1024];
while (sqlDBFile->good() ) {
WCHAR szAnsiBuffer[1024];
sqlDBFile->getline(szAnsiBuffer, 1024, L'\n');
int jdx = 0;
WCHAR *szBufferLine = new WCHAR[1024];
for (int i = 2; i < 1024; ++i) {
szBufferLine[jdx] = szAnsiBuffer[i];
i++;
jdx++;
}
int iLength = wcslen(szBufferLine);
szBufferLine[iLength] = L'\0';
if ((wcsncmp( szBufferLine, L"GO", wcslen(L"GO") )) != 0) {
wcsncat_s(pzSQLCommand, wcslen(pzSQLCommand), szBufferLine, wcslen(szBufferLine) );
pzSQLCommand[wcslen(pzSQLCommand) + 1] = L'\0';
break;
}
else {
hr = pICommandText->SetCommandText( DBGUID_DBSQL, pzSQLCommand );
hr = pICommandText->QueryInterface( IID_ICommandProperties, ( void ** ) &pICommandProperties );
hr = pICommandText->Execute( NULL, IID_IRowset, NULL, &cRowsAffected, ( IUnknown ** ) &pIRowset );
}
}
}
|
|
|
|
|
WCHAR szAnsiBuffer[1024];
sqlDBFile->getline(szAnsiBuffer, 1024, L'\n');
int jdx = 0;
WCHAR *szBufferLine = new WCHAR[1024];
for (int i = 2; i < 1024; ++i) {
szBufferLine[jdx] = szAnsiBuffer[i];
i++;
jdx++;
}
int iLength = wcslen(szBufferLine);
szBufferLine[iLength] = L'\0';
I'm not sure what you are trying to do here but most of this code is redundant. You have defined your input buffer as WCHAR so the resulting line will be Unicode, There is no need (in fact it's quite dangerous) for the copying character by character. All you need is:
WCHAR szBufferLine[1024];
sqlDBFile->getline(szBufferLine, 1024, L'\n');
This will leave you with a null terminated array of Unicode characters in szBufferLine , which you can then test, for the L"GO" string, and append to your command.
A couple of other things that you should also do:
1. When you create the pzSQLCommand buffer, is to add a null at the beginning so your wcsncat_s() calls do not trash your memory, thus:
WCHAR *pzSQLCommand = new WCHAR[1024];
*pzSQLCommand = L'\0';
2. Use the proper length setting of your destination buffer (see here[^]) in your wcsncat_s() call thus:
wcsncat_s(pzSQLCommand, 1024, szBufferLine, wcslen(szBufferLine) );
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
The code is for reading a sql text file, which is exported from sql management. By running the file, you can create a database and populate the data.
It's weird, or I'm reading the results wrong, but on get line, I get the every other character just like the socket program I wrote. I guess I am misinterpreting the data, and it is real unicode, with the 2nd character not programmed.
So one of the original code modules I had was like yours except for the small changes, but I was using ofstream, that kept erasing my file.
The cat works now since placing the null terminator in the creation of the pzSQLCommand, but only cats the first character "y", for "p" must be a special character that halts the copy. I need to walk through it and see.
The getline command returns this. LC 0 LR 0 LE 0 LA 0 LT 0 LE 0 and so on
+ szCommandLine 0x0012f0e0 "ÿþC" wchar_t [1024]
The first file line, plus rest of command for reference
CREATE TABLE [dbo].[BatchSettlementIndex] (
[BatchID] int IDENTITY(1, 1) NOT NULL,
[BatchName] varchar(80) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[BatchDate] datetime NULL,
[BatchAmount] decimal(10, 2) NULL
)
ON [PRIMARY]
GO
I guess I should move forward 1 move and get the next line working first, since the mechanics are better now. Your wisdom has solidified the design, in which I thank you for. If you think of something let me know.
FYI:
I'm almost done with all the little programs I need for my wizard. This is the next to last piece I need, then I can take all the parts, and compile them into some dll's within the project, and make a new gui to support them.
It's to the point where I have gone far beyond the need of InstallShield 2012, and will try the stock deployment to deploy this program, and let it download the asp.net stuff I wrote.
|
|
|
|
|
Well that was fast. The nextline works now. One more to go here, I'll work on the first 2 characters when I get back in 3 hours.
std::wifstream *sqlDBFile = new std::wifstream;
sqlDBFile->open(szFilePath, std::wifstream::in);
if (sqlDBFile->is_open() ) {
while (sqlDBFile->good() ) {
WCHAR *pzSQLCommand = new WCHAR[1024];
*pzSQLCommand = L'\0';
while ( sqlDBFile->get() ) {
WCHAR szCommandLine[1024];
sqlDBFile->getline(szCommandLine, 1024, L'\n');
if (szCommandLine != L"GO") {
wcsncat_s(pzSQLCommand, 1024, szCommandLine, wcslen(szCommandLine) );
break;
}
else {
hr = pICommandText->SetCommandText( DBGUID_DBSQL, pzSQLCommand );
hr = pICommandText->QueryInterface( IID_ICommandProperties, ( void ** ) &pICommandProperties );
hr = pICommandText->Execute( NULL, IID_IRowset, NULL, &cRowsAffected, ( IUnknown ** ) &pIRowset );
}
}
}
sqlDBFile->close();
sqlDBFile = NULL;
}
|
|
|
|
|
You got it. Remember WCHAR is a 16 bit character set, many of which map 1:1 with the ASCII set padded with a zero byte, which is why it looks like an ASCII character followed by a zero.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
i've some code written as a dll in C++ in Visual Studio 2008. I've to be able to debug it. But i can't load dll in test exe. There isn't any problem on my test exe because when i try to load another dll there isn't any problem. Dll that given to me builded in debug unicode. Is it may be the cause of the problem? And how can i convert it to just debug mode? i really need your help., Thanks in advance.
|
|
|
|
|
The debug and debug unicode project settings load different versions of the Microsoft MFC libraries and DLLs.
All of your MFC based projects, need to be compiled and built with the same project settings.
|
|
|
|
|
So, as the other poster said, rebuld your test exe with unicode debug set. (Hope you used the _T before all strings to enable the project to be built both ways.)
==============================
Nothing to say.
|
|
|
|
|
It makes no difference how the DLL is built as to whether you can use it or not, you just have to use the correct calling sequences. It would be better if you explained exactly what you are doing or trying to do, show some code if it will help, and what results you see.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Hello Friends
I am creating a Function template Whose declaration is like this
template <class T>
void Test(string name,T value,bool exist)
Defination
template<class T> void sample::Test(string name,T value,bool Exist)
Now,i am passing Color class object to fn Test,like this
Color c;
Test<Color>("name",c,true);
And Its Giving Linking error that
error LNK2019: unresolved external symbol "public: void __thiscall sample::Test<class color="">
Any Ideas?
Regards
Yogesh
|
|
|
|
|
Where did you put such statements?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I put these statements in my program.
I provide the overview of what i am Doing.
Regards
Yogesh
|
|
|
|
|
'my program' is a bit vague. Do you know, for instance, that template method implementations should go into header files (not into source files)?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
(unless you are only going to use that template inside that one source file)
|
|
|
|
|
Good point.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I was putting separate in header and cpp files.
Now,i put its definition in header itself.No Errors.
Will u please Explain Why it is so ?
Thanks & Regards
Yogesh
|
|
|
|
|
|
Hi, good resource!
Cheers, AT
Cogito ergo sum
|
|
|
|
|
good morning
i'm using VC++ in visual studio 2010
in my code i made a dialog with edit controls and an associated ON_EN_CHANGE function
i noticed this function (the OnChangeXXX associated with ON_EN_CHANGE handler) is called before dialog is visualized and the following error "Debug Assertion Failed!" appares
i can avoid it using only using a flag cleared at initialization and setted at the end of OnInitDialog, checked at the begin of my OnChangeXXX funcions, like this
if (!m_xIsUsable) return;
to ignore the function if dialog is not yet displayed
is this the only way to avoid the problem?
thanks in advance and regards
|
|
|
|
|
Does any of your edit fields have a spin button with UDS_AUTOBUDDY/UDS_SETBUDDYINT style attached to it? I ran into a similar problem a few days ago and -at least i think- the edit change is triggered by the spin control when it attaches itself to the edit and sets its content and since this happens at creation time you get the message before your DoDataExchange has ran. I avoided this by simply checking the m_hWnd member of the CEdit to see if it has been attached to the dialog's control or not. Could this be your problem also?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
hi Code-o-mat
you are right. i use a spin button associated
so i understand why not all my edit controls suffer about this problem. it could be nice to understand why there is not a latch in message dispatcher to block these kind of messages before window displaying is not complete
thank you very much for your suggestion 
|
|
|
|
|
I supose they either didn't think of this case OR since it is relatively easy to overcome, they didn't bother... anyways, yourwelcome.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
Hi
I have an application Exe that call a COM dll.
I have to Load an other Win32 dll(named "Win32_dll" from this COM dll.
LoadLibrary(Win32_dll) fail always.
HINSTANCE hLib = ::LoadLibrary(_T(_DLL_NAME_));
always hLib = NULL;
- I put this dll in the same directory of COM dll BUT always fail.
- I put it in the directory of EXE and it success.
So problem is how to Load the Win32 dll from the COM dll attached to an other Exe application ?
|
|
|
|
|