|
Razanust wrote: struct record;
remove the ';' there and see.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
Wow! Your code has so many problems. For example, how exactly does the while() loop end?
Razanust wrote: My object is to read the text file containing the name and ages of the students, character by character and then store them in a structure.
See here.
You could also use fscanf() like:
fscanf(fp, "%s %d", r.name, &r.age);
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
hi
i need an edit ctrl for entering numerical values. sometimes these values must lie in a specified range. otherwise, i want to warn the user by changing the edit-box color.
i derived a class from CEdit for this purpose and tried to put the code in the CtlColor:
HBRUSH MyEdit::CtlColor(CDC* pDC, UINT nCtlColor)
{
if (d_chars==decimalChars)
{
CString s;
GetWindowText(s);
USES_CONVERSION;
int val=atoi(T2A(s));
if (val<d_minVal || val>d_maxVal)
{
pDC->SetTextColor(RED);
pDC->SetBkColor(YELLOW);
}
}
return NULL;
}
i don't need to change the default brush used for painting the ctrl, so i return NULL. but this doesn't work. i tried returning a valid handle to a brush i created, but i could at most change the background color, not the text color.
what's the problem?
what's the best solution?
thx
|
|
|
|
|
ilostmyid2 wrote: derived a class from CEdit for this purpose
This is not correct.
WM_CTLCOLOR is sent to the parent window.
So you should be handling OnCtlColor of the parent dialog.
In that, check if the message is for your particular edit control and then do pDC->SetTextColor .
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
MyEditBox::MyEditBox()
{
m_brush = NULL;
itemData = NULL;
}
MyEditBox::~MyEditBox()
{
delete m_brush;
}
BEGIN_MESSAGE_MAP(MyEditBox, CEdit)
ON_WM_CTLCOLOR_REFLECT()
END_MESSAGE_MAP()
bool MyEditBox::SetColorScheme(COLORREF brushColor, COLORREF bgTextColor, COLORREF fgTextColor)
{
delete m_brush;
m_brush = new CBrush(brushColor);
bgc = bgTextColor;
fgc = fgTextColor;
Invalidate();
UpdateWindow();
return (m_brush != NULL);
}
void MyEditBox::ResetColorScheme()
{
delete m_brush;
m_brush = NULL;
Invalidate();
UpdateWindow();
}
HBRUSH MyEditBox::CtlColor(CDC* pDC, UINT nCtlColor)
{
if (m_brush == NULL)
return NULL;
pDC->SetTextColor(fgc);
pDC->SetBkColor(bgc);
return (HBRUSH)m_brush->GetSafeHandle();
}
|
|
|
|
|
I have created an MFC app as a SDI supporting doucment/view architecture. The main classes are: CMainFrame, CView, and CDocument. In my app I want to dynamically create a CListView when the user select a menu item. I've added CListView class to my project. In my OnInitialUpdate() I'm doing InsertColumn() calls and in OnUpdate() I'm doing InsertItem() and SetItemText(). When a menu item is select I am basically set a point to a new CListView object. What is not working is that nothing is being displayed on the screen !!! I know once the memory is allocated for the new CListView object I need to call Create() function. Don't know what I need to pass or how to link this to my CView class so that it is acutally displayed. Please help. I have not seen any good examples on dynamically creating a CListView object.
|
|
|
|
|
|
Thank for you the links. I changed my app to use multiple views in SDI. Good examples.
|
|
|
|
|
My object is to fill the buffer first and then make it empty. But the 'sizeof' command is returning the value '1', whatever input i give to it. Why? The code is mentioned below.
#include<stdio.h>
#include<conio.h>
main()
{
char dec;
static char ch[100];
int n=0,i,p,c,count;
while(1)
{
ch[n]=getche();
n=n+1;
if ( ch[n-1]=='\r')
break;
}
count=sizeof(ch[100]);
printf("%ld",count);
printf("Your name is");
for (c=0;c<count;c++)
{
printf(" %c",ch[c]);}
printf("\n\nWant to delete the array?");
dec=getche();
if (dec=='y')
{
for (i=0;i<99;i++)
ch[i]=0;
}
if (dec=='y')
{
for(p=0;p<99;p++)
printf("%c",ch[p]);
}
}
|
|
|
|
|
Razanust wrote: But the 'sizeof' command is returning the value '1'
It returns 1 and that is correct, because this is the size of a char type.
If you need the count of the elements in array, you have to use _countof macro -> here.[^]
This form here: count = _countof(ch) will always return 100, because you actualy allocated memory for 100 elements on the stack. But note that the variable "n" from your code holds the count of the characters.
Razanust wrote: count=sizeof(ch[100]);
Also note that your use of sizeof is wrong. If you need the size of an array in bytes, than you must change it to: sizeof(ch) .
Best wishes!
Nuri
modified on Tuesday, June 30, 2009 3:07 PM
|
|
|
|
|
If by 'whatever input' you mean the number you put in the square brackets for ch[100], I think this is because ch[n] is always going to be a pointer. It's equivalent to
<br />
char *ch = (char*)malloc(sizeof(char) * n);<br />
then sizeof(ch) will always be 1 because it's pointing to the start of your array. In C, you sort of always have to keep track of the size of your arrays manually.
|
|
|
|
|
thebeekeeper wrote: because ch[n] is always going to be a pointer
Nope.
ch is a pointer, ch[n] is one character out of an array of characters, that is why its size is 1.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
ha! I forgot that [] are for indexing into arrays!
|
|
|
|
|
OK - that's not how sizeof works - it tells you the size of a type, either via the typename ('sizeof (char)') or a compile-time static expression ('sizeof (3 * 4.0)'). The WIkipedia entry[^] is quite accurate.
I presume you know you can use n to tell you how many characters have been entered...
Razanust wrote: printf("\n\nWant to delete the array?");
dec=getche();
if (dec=='y')
{
for (i=0;i<99;i++)
ch[i]=0;
}
Can I suggest you read up how strings (specifically null terminated strings) and arrays work in C?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Razanust wrote: count=sizeof(ch[100]);
As a side note, your code (possibly) does not own the memory at location ch[100] . While that variable holds 100 chars, they are numbered 0-99.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I am new for vc++, i am doing project on vc++2008 clr base windows form application. not able to use inpout.dll in my project please help. if possible give example. thanks
|
|
|
|
|
It will be hard without a header and lib files to import DLL to your application. There are other alternatives as well.
Anyway See <a href="http://msdn.microsoft.com/en-us/library/kh1zw7z7(VS.71).aspx">this</a>[<a href="http://msdn.microsoft.com/en-us/library/kh1zw7z7(VS.71).aspx" target="_blank" title="New Window">^</a>]
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Hi, i need to be able to create a C++ dll that can be call from JAVA or PHP can someone help me get in the right direcction to accomplish this?.
By the way can someone tell if the C++ dll that can be called from Visual Basic can be called from JAVA or PHP too?
printf("Error: No keyboard found!");
printf("Press any key to continue");
|
|
|
|
|
Calling C++ from Java[^] - or there's this option[^] - I've used JNI successfully, never used J/Invoke.
Writing a PHP extension in C++[^] seems to be the accepted way of making native code available to PHP.
I have (recently) written code (a DLL) that was available to Java, VB6 and C/C++ - I did that by making different entry-points for each language. The Java and VB entry-points are just shims that convert Java/VB data types into native ones, call into the C/C++ entry point and then convert data types back into Java/VB on the way out. It works fine.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Does anybody know the details of how linking works in VS2005 vs Qt? Namely, QtCreator. I've got an app I'm writing that uses a 3rd party library, and it works correctly when I build the project in VS2005, but not when I build in QtCreator. Everything seems to link correctly in both cases, so I'm sort of at a loss.
The error I get when I build with QtCreator is an access violation error. It seems like my code is calling into an invalid memory location. I can see that the function has an address with something like cout << SomeFunction << endl; but that doesn't tell me a whole lot besides that it's not null.
Maybe the runtime is doing something different? When I look at my exe in depends, I get some strange results. Both versions (VS and Qt) show my exe pointing at the correct dlls, but in the Qt one I don't get any entries in the "Parent Import Function List View" but I do get entries when I build with VS. I feel like that bit of information is pointing out something obvious to me, but I can't figure out what it is.
Nick
|
|
|
|
|
thebeekeeper wrote: in the Qt one I don't get any entries in the "Parent Import Function List View"
Sounds like Qt is static linking against the run-time? Are you using the same code generation/runtime library options to build Qt as you are building against Qt?
Does QtCreator use Visual C++? I had a remembrance that it used gcc?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I am accessing a DLL written in VB which has a number of methods. This DLL is designed to sign onto a sqlserver database and return various information depending on the methods called.
To date I have managed to CoCreateInstance and successfully access several of these methods.
My issue is this: Several of these methods return a record set with possibly multiple rows of data and I have no idea how to create a record set in VC++ and how access it.
This is the description of one of the methods I am trying to use:
<br />
GetCustomerList()<br />
Returns a RecordSet of all customer fields<br />
<br />
Required Properties<br />
LastName<br />
<br />
RecordSet Layout<br />
uidCustomerID<br />
strCustNo<br />
strMem_Ext<br />
strTitle<br />
strFirstName<br />
strMiddleInitial<br />
strLastName<br />
In code (I have removed pieces to make it easier to read), you can see how I have accessed some of the methods:
The method GetCustomerList requires the property of LastName to be set prior to calling and will return a RecordSet of all the Customers with the last name given.
How do I construct this record set and walk through it?
Thanks for all help
Phil
_WebRes *wr;
hresult=CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, __uuidof(_WebRes), (LPVOID *)&wr);
bool bCon = wr->Connect("GXX", "");
bool bSUser = wr->SetUser("GXX");
BSTR bstrMess;
wr->FirstName = "Davis";
wr->LastName = "Phil";
wr->PhoneNo = "123 456 7890";
wr->Display = "Davis, Phil";
wr->Email = "phil@email.com";
bool bCust = wr->CreateCustomer(&bstrMess);
CString str(bstrMess);
MessageBox(str);
wr->LastName = _bstr_t ("Davis");
Record Set = wr->GetCustomerList();
|
|
|
|
|
Well....what defines the RecordSet structure? Is it the DLL written in VB6? Does it return ADO record-sets? That's the first thing you need to find out, anyway, so you can pull in some artefact that defines the recordset structure within your C++ program.
Once you've done that, it's relatively simple. Have a look at this post[^] I recently made showing how to use ADO connections and recordsets - they're COM objects. If you use #import to pull in the COM library's type library, it's pretty simple.
|
|
|
|
|
Hi Stuart,
Thank you for responding.
Some answers to you questions:
The DLL is written in VB6.
Yes, the record set is defined in the DLL.
I don't know what kind of record-sets it returns, ADO or otherwise.
Yes, I do use #import and a .tli and a .tlh are generated.
I have included the .tlh if that helps.
Does that help us reach the next stage?
Thanks
Phil
#pragma once
#pragma pack(push, 8)
#include <comdef.h>
struct __declspec(uuid("e897466c-75b0-459f-9512-21d42e1f5703"))
__TTExt;
struct __declspec(uuid("dc8718c4-d07f-4542-a799-f2015a0614cf"))
_WebRes;
struct WebRes;
_COM_SMARTPTR_TYPEDEF(_WebRes, __uuidof(_WebRes));
struct __declspec(uuid("dc8718c4-d07f-4542-a799-f2015a0614cf"))
_WebRes : IDispatch
{
__declspec(property(get=GetLastError))
_bstr_t LastError;
__declspec(property(get=GetDatabase,put=PutDatabase))
_bstr_t Database;
__declspec(property(get=GetServer,put=PutServer))
_bstr_t Server;
__declspec(property(put=PutResNotes))
_bstr_t ResNotes;
__declspec(property(get=GetReservationID))
_bstr_t ReservationID;
__declspec(property(get=GetConfirmationNumber))
_bstr_t ConfirmationNumber;
__declspec(property(put=PutVoucherNo))
long VoucherNo;
__declspec(property(put=PutNumberOfPlayers))
long NumberOfPlayers;
__declspec(property(put=PutSelectedSlot))
_bstr_t SelectedSlot;
__declspec(property(put=PutPlayDate))
DATE PlayDate;
__declspec(property(put=PutEndTime))
DATE EndTime;
__declspec(property(put=PutStartTime))
DATE StartTime;
__declspec(property(put=PutTee))
_bstr_t Tee;
__declspec(property(put=PutFacility))
_bstr_t Facility;
__declspec(property(get=GetCustomerID,put=PutCustomerID))
_bstr_t CustomerID;
__declspec(property(put=PutCreditCardExpDate))
_bstr_t CreditCardExpDate;
__declspec(property(put=PutCreditCard))
_bstr_t CreditCard;
__declspec(property(put=PutEmail))
_bstr_t Email;
__declspec(property(put=PutFaxNo))
_bstr_t FaxNo;
__declspec(property(put=PutPhoneExt))
_bstr_t PhoneExt;
__declspec(property(put=PutPhoneNo))
_bstr_t PhoneNo;
__declspec(property(put=PutCountry))
_bstr_t Country;
__declspec(property(put=PutState))
_bstr_t State;
__declspec(property(put=PutCompany))
_bstr_t Company;
__declspec(property(put=PutCity))
_bstr_t City;
__declspec(property(put=PutZip))
_bstr_t Zip;
__declspec(property(put=PutDisplay))
_bstr_t Display;
__declspec(property(put=PutAddress2))
_bstr_t Address2;
__declspec(property(put=PutAddress1))
_bstr_t Address1;
__declspec(property(put=PutMidInitial))
_bstr_t MidInitial;
__declspec(property(put=PutFirstName))
_bstr_t FirstName;
__declspec(property(get=GetLastName,put=PutLastName))
_bstr_t LastName;
_variant_t GetCustomerList ( );
VARIANT_BOOL CreateCustomer (
BSTR * ReturnMessage );
_variant_t GetFacilityList ( );
_variant_t GetSlotsAvailable ( );
VARIANT_BOOL CreateReservation (
BSTR * ReturnMessage );
_variant_t GetReservationsForConfirmationNo (
_bstr_t ConfirmationNo );
VARIANT_BOOL CancelReservation (
_bstr_t ReservationID,
BSTR * ReturnMessage );
_variant_t GetServers ( );
VARIANT_BOOL Connect (
_bstr_t vendor_name,
_bstr_t ini_path );
VARIANT_BOOL Connect1 (
_bstr_t Server,
_bstr_t Database );
_bstr_t GetLastName ( );
void PutLastName (
_bstr_t _arg1 );
void PutFirstName (
_bstr_t _arg1 );
void PutMidInitial (
_bstr_t _arg1 );
void PutAddress1 (
_bstr_t _arg1 );
void PutAddress2 (
_bstr_t _arg1 );
void PutDisplay (
_bstr_t _arg1 );
void PutZip (
_bstr_t _arg1 );
void PutCity (
_bstr_t _arg1 );
void PutCompany (
_bstr_t _arg1 );
void PutState (
_bstr_t _arg1 );
void PutCountry (
_bstr_t _arg1 );
void PutPhoneNo (
_bstr_t _arg1 );
void PutPhoneExt (
_bstr_t _arg1 );
void PutFaxNo (
_bstr_t _arg1 );
void PutEmail (
_bstr_t _arg1 );
void PutCreditCard (
_bstr_t _arg1 );
void PutCreditCardExpDate (
_bstr_t _arg1 );
_bstr_t GetCustomerID ( );
void PutCustomerID (
_bstr_t _arg1 );
void PutFacility (
_bstr_t _arg1 );
void PutTee (
_bstr_t _arg1 );
void PutStartTime (
DATE _arg1 );
void PutEndTime (
DATE _arg1 );
void PutPlayDate (
DATE _arg1 );
void PutSelectedSlot (
_bstr_t _arg1 );
void PutNumberOfPlayers (
long _arg1 );
void PutVoucherNo (
long _arg1 );
_bstr_t GetConfirmationNumber ( );
_bstr_t GetReservationID ( );
void PutResNotes (
_bstr_t _arg1 );
void PutServer (
_bstr_t _arg1 );
void PutDatabase (
_bstr_t _arg1 );
VARIANT_BOOL SetResellerCode (
_bstr_t InterfaceResellerCode );
VARIANT_BOOL SetUser (
_bstr_t Name );
_bstr_t GetLastError ( );
_bstr_t GetServer ( );
_bstr_t GetDatabase ( );
virtual HRESULT __stdcall raw_GetCustomerList (
VARIANT * _arg1 ) = 0;
virtual HRESULT __stdcall raw_CreateCustomer (
BSTR * ReturnMessage,
VARIANT_BOOL * _arg2 ) = 0;
virtual HRESULT __stdcall raw_GetFacilityList (
VARIANT * _arg1 ) = 0;
virtual HRESULT __stdcall raw_GetSlotsAvailable (
VARIANT * _arg1 ) = 0;
virtual HRESULT __stdcall raw_CreateReservation (
BSTR * ReturnMessage,
VARIANT_BOOL * _arg2 ) = 0;
virtual HRESULT __stdcall raw_GetReservationsForConfirmationNo (
BSTR ConfirmationNo,
VARIANT * _arg2 ) = 0;
virtual HRESULT __stdcall raw_CancelReservation (
BSTR ReservationID,
BSTR * ReturnMessage,
VARIANT_BOOL * _arg3 ) = 0;
virtual HRESULT __stdcall raw_GetServers (
VARIANT * _arg1 ) = 0;
virtual HRESULT __stdcall raw_Connect (
BSTR vendor_name,
BSTR ini_path,
VARIANT_BOOL * _arg3 ) = 0;
virtual HRESULT __stdcall raw_Connect1 (
BSTR Server,
BSTR Database,
VARIANT_BOOL * _arg3 ) = 0;
virtual HRESULT __stdcall get_LastName (
BSTR * _arg1 ) = 0;
virtual HRESULT __stdcall put_LastName (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_FirstName (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_MidInitial (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_Address1 (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_Address2 (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_Display (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_Zip (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_City (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_Company (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_State (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_Country (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_PhoneNo (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_PhoneExt (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_FaxNo (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_Email (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_CreditCard (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_CreditCardExpDate (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall get_CustomerID (
BSTR * _arg1 ) = 0;
virtual HRESULT __stdcall put_CustomerID (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_Facility (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_Tee (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_StartTime (
DATE _arg1 ) = 0;
virtual HRESULT __stdcall put_EndTime (
DATE _arg1 ) = 0;
virtual HRESULT __stdcall put_PlayDate (
DATE _arg1 ) = 0;
virtual HRESULT __stdcall put_SelectedSlot (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_NumberOfPlayers (
long _arg1 ) = 0;
virtual HRESULT __stdcall put_VoucherNo (
long _arg1 ) = 0;
virtual HRESULT __stdcall get_ConfirmationNumber (
BSTR * _arg1 ) = 0;
virtual HRESULT __stdcall get_ReservationID (
BSTR * _arg1 ) = 0;
virtual HRESULT __stdcall put_ResNotes (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_Server (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall put_Database (
BSTR _arg1 ) = 0;
virtual HRESULT __stdcall raw_SetResellerCode (
BSTR InterfaceResellerCode,
VARIANT_BOOL * _arg2 ) = 0;
virtual HRESULT __stdcall raw_SetUser (
BSTR Name,
VARIANT_BOOL * _arg2 ) = 0;
virtual HRESULT __stdcall get_LastError (
BSTR * _arg1 ) = 0;
virtual HRESULT __stdcall get_Server (
BSTR * _arg1 ) = 0;
virtual HRESULT __stdcall get_Database (
BSTR * _arg1 ) = 0;
};
struct __declspec(uuid("d00de9f1-98eb-4cd9-8685-0ea4f283971f"))
WebRes;
#include "c:\documents and settings\phild\my documents\visual studio code\vbdll\vcclient\debug\ttext.tli"
#pragma pack(pop)
modified on Tuesday, June 30, 2009 12:20 PM
|
|
|
|
|
Heh - it's in a variant. That makes things a little more tricky
I still reckon it could well be an ADO recordset - ADO plays nicely with VB and SQL Server. So, #import the ADO libraries (as shown in the post I linked to earlier - look for the 'Debug Assertion' thread) and try assigning the result of GetCustomerList to a variable of type ADODB::_RecordsetPtr - the _com_ptr_t class has a constructor that takes a variant and attempts to extract an IUnknown pointer and QueryInterface for the interface you first thought of.
[edit]If your recordset pointer isn't an ADO recordset pointer, an exception'll get thrown, so you'll soon know that it's failed![/edit]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|