|
I agree. MC++ and C-hash has nothing to do with C++ (even that this forum is really Visual C++ which isn't C++ by a longshot).
|
|
|
|
|
Hi,
I'm trying to create dsn's programatically for an installation I'm doing. When I create them either by setting the registry setting (ID: Q184608) or calling the following:
<br />
#include "stdafx.h"<br />
<br />
#include "stdio.h"<br />
#include "windows.h"<br />
#include "sql.h"<br />
#include "odbcinst.h"<br />
<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
RETCODE retcode;<br />
<br />
retcode = SQLConfigDataSource(NULL,<br />
ODBC_ADD_DSN,<br />
"SQL Server",<br />
"DSN=MY_TEST\0"<br />
"LastUser=test_user\0"<br />
"Database=test_database\0"<br />
"Driver=C:\\WINNT\\System32\\sqlsrv32.dll\0"<br />
"Server=test_server\0\0");<br />
<br />
return 0;<br />
}<br />
The DSN doesn't show up in the ODBC Data Source Administrator. I even exported the settings from the registry to make sure everything was being set correctly.
Can anyone point me in the right direction as to why they don't show up?
Thanks in advance,
Craig
|
|
|
|
|
Hi Guys I an trying to read in a binary file to a variable called buffer.
See code below
buffer is defined as char *
but when I debug code, buffer only seems to hold the first character from the file.
What I am trying to achieve is to read in the file search it for a particular string and when I find
this string, read in the entry in the file which is x characters after the first found string
I know 'seekg' can read in characters from a given position.... but firstly I have to find the position
of a particular string in the file.
The file is an SQL Server Profiler trace file.
Is there some other way I can do this - Is there any way I can serach the file without reading it in...
or do I need to declare buffer in a different way.
Any ideas would be appreciated
Cheers
=====================================================
// readbinaryfile.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream.h>
#include <fstream.h>
#include <string.h>
const char * filename = "C:\TenforeFeed.trc";
char * buffer;
long size;
char * pch;
int main(int argc, char* argv[])
{
ifstream file (filename, ios::in|ios::binary|ios::ate);
if(file.is_open())
{
size = file.tellg();
file.seekg (0, ios::beg);
buffer = new char [size];
file.read (buffer, size);
cout << buffer[3];
//delete[] buffer;
}
return 0;
}
========================================================
|
|
|
|
|
I'm assuming, the value returned by tellg is the correct value. If so, try it with a file you construct using Notepad. If the file contains UNICODE data, typically, every other byte is 0. This causes the string to look like it is only one character long.
Hope this helps,
Bill
|
|
|
|
|
Use wchar_t instead of char
|
|
|
|
|
Hi guys,
All the code that I have ever written has been for the standard english version of windows. Recently, though, my company has been talking about sending our software overseas to some of our partners. The people that will be using it will speak english so I won't have to get menus, titlebars and things like that translated. BUT I know that they will connecting to databases that use different character sets. (I don't have access to a nonenglish version of Windows or SQL server yet.) Can you guys give me some tips on using Unicode or anything that I should look out for.
I guess I'm wondering about things like when to use TCHAR, _T() and if CString holds up inplace or do I have to rewrite things. Any tips or things to watch out for would be greatly appreciated.
Here is some code that I'm thinking of using it would connect to a db and bring back a list of tables from a combobox selected database will it work for double byte unicode?
----------------------------------------------------
//Get the User selected db from the combobox
CString db = _T("");
m_cmbDatabases.GetLBText(m_cmbDatabases.GetCurSel(),db);
//Open a new conncetion to the User selected db
//m_Server,m_LoginName,m_Password are CStrings returned from a dlg
CString strConnection = _T("");
strConnection.Format("driver={SQL Server};server=%s;uid=%s;pwd=%s;database=%s",m_Server,m_LoginName,m_Password,db);
if(DB.Open(strConnection))
{
//Update m_lstTables
CString Tablename = _T("");
RS = CERecordset(&DB);
if(RS.Open("SELECT name FROM sysobjects WHERE type = 'U' order by name"))
{
m_lstTables.ResetContent();
while(!RS.EOF())
{
RS.GetField("name",Tablename);
m_lstTables.AddString(Tablename);
----------------------------------------------------
|
|
|
|
|
You should use _T() for any literal strings in your source.
So, the Format() call should be:
strConnection.Format(_T("driver={SQL Server};server=%s;uid=%s;pwd=%s;database=%s"),m_Server,m_LoginName,m_Password,db);
and any other call that uses literal strings should also have the _T().
I haven't used CERecordSet, so I don't know if it is Unicode aware. Is the Open() call specified to take an LPCTSTR (or a CString)? Does the GetField() member take an LPCTSTR (or a CString)?
You should look at the MSDN documentation for "Strings: Unicode and Multibyte Character Set (MBCS) Support". They do a pretty good job describing what to look for when using Unicode.
Best regards,
John
|
|
|
|
|
i have been using CToolBar but it only allows 16 colors (as far as I can tell).. so i tried switching to CToolBarCtrl.. but I never get any toolbar to appear.. can someone tell me what in my code is causing the toolbar to not show up, also does the AddButtons() command only take one TBBUTTON at a time?
I've been looking through msdn and on CP today, but can't find a basic example of thie CToolBarCtrl that works, as most of them call a command GetToolBarCtrl() which isn't a member of CToolBarCtrl, but rather CToolBar.. any help would be much appreciated!
i just want the toolbar to show up, from there i can add all my other button code:
m_wndToolBar.CreateEx(WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, WS_CHILD, CRect(CPoint(0,0),CPoint(500,510)), this, IDR_MAINFRAME);
m_wndToolBar.AddBitmap(17, IDB_SCTOOLBAR);
TBBUTTON btn;
btn.fsStyle = TBSTYLE_BUTTON;
btn.fsState = TBSTATE_ENABLED;
btn.idCommand = ID_FILE_NEW;
btn.iBitmap = 1;
m_wndToolBar.AddButtons(1, &btn);
also, what is the point of the CRect getting passed in the CreateEx? I have no idea what size CRect to pass here..
thanks!
-dz
|
|
|
|
|
If all you want is more than 16 colors, that is easily possible with the normal MFC toolbar support. Here is the process:
- Create the toolbar normally in the resource editor
- Edit the toolbar bitmap manually, converting it to high color
- The bitmap will be converted to 16 colors by MFC when it is loaded, so you will use the following code (nResourceId is the toolbar resource identifier, and m_toolbar is the CToolBar object):
HBITMAP hBmp = static_cast<HBITMAP>(LoadImage(AfxGetResourceHandle(),
MAKEINTRESOURCE(nResourceId), IMAGE_BITMAP,
0, 0, LR_SHARED | LR_LOADMAP3DCOLORS));
m_toolbar.LoadToolBar(nResourceId);
m_toolbar.SetBitmap(hBmp);
--------
And we die young.
Faster we run. Alice in Chains, We Die Young
|
|
|
|
|
thank you so much! this worked great!
-dz
|
|
|
|
|
I have created the control derivative from CEdit .
Inside him, from the right side, it is necessary for me to arrange CScrollBar .
I have two questions:
1. How correctly to choose ID for him?
2. Where correctly to create CScrollBar (standard scrolling does not approach, because it is necessary for me to create CScrollBar smaller length than height of the control)?
Excuse, if my questions will seem children's
Best regards,
Eugene Pustovoyt
Eugene Pustovoyt
Sonork ID 100.10002:Yaumen
|
|
|
|
|
1. Any non 0 value should be OK. You will be creating the scrollbar as a child of the edit control, so it will not be clashing with anything else unless your CEdit derived class has a lot of child windows.
2. You can create the scroll bar in the OnCreate of your CEdit controls derived class. Call the base class first then create the scroll bar. You will also need to override the OnSize() to correctly possition the scrollbar in the CEdit's client area. Don't forget to check that the window is valid before calling MoveWindow on it.
Roger Allen
Sonork 100.10016
yet to be identified being from the planet Paltinmoriumbanfrettybooter
|
|
|
|
|
I tried to use OnCreate , but at use SubclassDlgItem() I do not get in OnCreate .
Therefore I have decided to create scroll bar in a PreSubclassWindow () method.
But there is one problem!!! I do not know exact height and a position scrollbar yet I shall not start draws the control in OnPaint. How to be in this case?
Best regards,
Eugene Pustovoyt
Sonork ID 100.10002:Yaumen
|
|
|
|
|
Ahh, that makes it more clear. Because you are sub-classing the item, this happens in a dialog OnInitDialog function. I would write a public function as part of the class to create the scrollbar. Something like this:
bool CMyEdit::CreateScrollBar()
{
CRect rect ;
GetClientRect(&rect) ;
if (!m_ScrollBar.Create(WS_CHILD | WS_VISIBLE | SBS_HORZ, rect, this, 1))
{
TRACE("Failed to create scroll bar\n") ;
return false ;
}
return true ;
}
You would then call this in the OnINitDialog after the control has been sub-classed.
Roger Allen
Sonork 100.10016
yet to be identified being from the planet Paltinmoriumbanfrettybooter
|
|
|
|
|
Thank for the help!!!
Now I create CScrollBar<code> in <code>PreSubclassWindow()
pVScroll.Create(WS_CHILD | WS_VISIBLE | SBS_VERT | SBS_RIGHTALIGN, CRect (0, 0, 100, 100), this, 100);
And then in function OnPaint() when becomes the sizes scrollbar are known, I do the following
pVScroll.MoveWindow(rect);
As far as I do correctly all?
Best regards,
Eugene Pustovoyt
Sonork ID 100.10002:Yaumen
|
|
|
|
|
It's better to move (resize) the scrollbar when your edit control gets a WM_SIZE , not WM_PAINT . A WM_PAINT handler should be as fast as possible.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I need to do some owner draw/ custom controls, and i dont have a clue
|
|
|
|
|
What king of control do you want? There are lots of sample in codeproject.
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
You may have a look at Chris' Creating Custom Controls or Create your own controls - the art of subclassing.
Regards
Thomas
Finally with Sonork id: 100.10453 Thömmi
Disclaimer: Because of heavy processing requirements, we are currently using some of your unused brain capacity for backup processing. Please ignore any hallucinations, voices or unusual dreams you may experience. Please avoid concentration-intensive tasks until further notice. Thank you.
|
|
|
|
|
Newbie Question!
I need the integer value in a 'command line char array' to increment with the for loop.
eg
On the first loop the cmdline[]="C:\\myexecutable --getmemory SM 1";
On the second loop the cmdline[]="C:\\myexecutable --getmemory SM 2";
On the third loop the cmdline[]="C:\\myexecutable --getmemory SM 3";
etc, for 10 loops.
I have tried the following
for(int i =1; i<=10; i++)
{
char strInitial[] = "C:\\myexecutable --getmemory SM ";
char cmdline[]=("%s [i]", strInitial);
...//snip
}
But I get the following error:
error C2440: 'initializing' : cannot convert from 'char *' to 'char []'
Or if I remove the ()'s
for(int i =1; i<=10; i++)
{
char strInitial[] = "C:\\myexecutable --getmemory SM ";
char cmdline[]="%s [i]", strInitial;
...//snip
}
Then I get the following error:
error C2040: 'strInitial' : 'char' differs in levels of indirection from 'char [49]'
Please help!
Thanks.
|
|
|
|
|
Try this
char szBuffer [256];
sprintf (szBuffer, "C:\\myexecutable --getmemory SM %i", i);
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Works great, Thanks a million!
|
|
|
|
|
hi ,
My application's architecture is as follows :
CMainFrm-->CMDIChildFrame-->CDialog
The MainFrame has instances of the MDIChildFrame . The child Frames display a Dialog . I need to pass a message from the Dialog to the MainFrame. What is the exact way to send a notification from the Dialog and write ,register a handler in my mainframe .
Please help
|
|
|
|
|
how could i make a window transparent for win32 not MFC
ta, any help will be greatful.
|
|
|
|
|
You can set the WS_EX_TRANSPARENT ex_style, but this will only work for Windows2000 and above. You can also use SetWindowRgn to make your window appear that it has holes in it.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|