|
i want to create an array whose size is dynamic. Each node of the array should be an array of characters of length 20.And then i want to send this as an argument in a function.
This is what i have done.....
<br />
char *m_strTemp[10] = new char[count];<br />
After getting the value of "count" i start filling the array.
Now to send it as an argument of a function i declared the function as follows.
void CIdentifyDlg::SetVariable(char *str[10])<br />
{<br />
char *tempStr[10] = new char[count];<br />
tempStr = str;<br />
}<br />
The function is called as follows
<br />
SetVariable(m_strTemp[10]);<br />
This is giving error.
Can anyone please help me out. Hope my question is clear....
|
|
|
|
|
nripun wrote:
This is giving error.
I give up. What's the error?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
nripun wrote:
char *m_strTemp[10] = new char[count];
here you allocate an array of 10 char pointers and assign the char pointer returned by new to element zero (m_strTemp[0]). It's not an array of 10 (valid) pointers to char arrays.
nripun wrote:
char *tempStr[10] = new char[count];
tempStr = str;
same issue as above. Furthermore, in the second line you set the pointer tempStr to point to the same location as str points to (which is an array of 10 char pointers, where the first one points to a valid array). You do not copy the data pointed to by str into the array pointed to by tempStr.
nripun wrote:
This is giving error.
which error?
I would use containers instead, either MFC containers or STL ones.
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Why don't you use std::string (from the Standard Template Library) or CString (from MFC) instead ?
It will look like this:
void CIdentifyDlg::SetVariable(std::string* StringsArray, int nCount)<br />
{<br />
for (int i=0;i<nCount;i++)<br />
{<br />
std::string TempString = StringsArray[i];<br />
}<br />
}<br />
|
|
|
|
|
can you please tell me how to store numbers in a CString object??
|
|
|
|
|
Why do you want to store numbers ???? The problem is exactly the same as a standard string except you don't need to manage the memory yourself...
But if you need to send integers then use an integer array instead (int*) that is much more easy than store the numbers into char strings (and how would you do that ???)
|
|
|
|
|
This is what i want to do..........
<br />
sprintf(m_strTemp[i],"%d)\t%lf%% Match",i+1,m_final);
But m_strTemp is CString. So it gives the following error.
sprintf' : cannot convert parameter 1 from 'class CString' to 'char *'
|
|
|
|
|
Use Format() from CString, it will gives you exactly the same results:
m_strTemp[i].Format("%d)\t%lf%% Match",i+1,m_final);
|
|
|
|
|
Thank You very much ............
|
|
|
|
|
nripun wrote:
SetVariable(m_strTemp[10]);
How about this?
SetVariable(m_strTemp);
John
|
|
|
|
|
I am programming a C++ MFC GUI application. During every execution of a for loop in my app I want the application to pause for about 1 second. How can I do this? I have been screwing around with WM_TIMER and SetTimer and KillTimer but I just can't get it to pause. Any help/examples would be a great help.
Thanks!
Lilli
|
|
|
|
|
You mean Sleep(1000) ?
But if your loop is in the main thread, your application will freeze also during 1 second...
|
|
|
|
|
I'm sensing a potentially bad design here. Why exactly do you need a one-second pause?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Yes, as if the souls of a million maintenance programmers were crying out in agony...
|
|
|
|
|
I am programming an Easter Egg into the app I am working on. When a user picks a certain color to change the background to, the application rapidly switches between 25 random colors before going to the color the user chose. It's funny, but I need there to be a brief ~.2 second delay on each color so you can see it. Sleep(200) worked PERFECTLY.
|
|
|
|
|
Timers looks much more appropriate for doing that !! With the Sleep, your application will freeze (and thus not respond to user commands) during the Sleep time... In general, the use of Sleep is usefull for some very specific cases...
|
|
|
|
|
Yes, like telling your app that it's time to do something.
|
|
|
|
|
Hallo,
i try with VisualC++ 6 to read the LDAP user list, but all the examples didn't work.
See the problem:
--------------------Konfiguration: Test5 - Win32 Debug--------------------<br />
Kompilierung läuft...<br />
Test5.cpp<br />
d:\program files\microsoft visual studio\vc98\include\iads.h(27) : error C2146:<br />
Syntaxfehler : Fehlendes ';' vor Bezeichner 'IADs'<br />
(Syntax error: missing ';' befor identifier 'IADs') <br />
d:\program files\microsoft visual studio\vc98\include\iads.h(27) : fatal error C1004:<br />
Unerwartetes Dateiende gefunden<br />
(unexpected file end found)<br />
Fehler beim Ausführen von cl.exe.<br />
<br />
Test5.exe - 2 Fehler, 0 Warnung(en)<br />
In the iads.h(27) you find this: "typedef interface IADs IADs;".
I think i forgot a compiler directive or a lib file, but i didn't find information in the tutorials and forums.
Thanks in advance!
Carl
|
|
|
|
|
I noticed one sample included this file as well:
#include <activeds.h>
Does that help at all?
|
|
|
|
|
Not real,
I know the samples on this pages and also on MSDN. From this i built this example:
<br />
#include "stdafx.h"<br />
#include <afxwin.h><br />
#include <activeds.h><br />
#include <Adshlp.h><br />
#include <iads.h><br />
<br />
int main(int argc, char* argv[])<br />
{<br />
HRESULT hr;<br />
IADS *pads;<br />
<br />
hr = ADsGetObject( L"LDAP://rootDSE", IID_IADs, (void**)&pads);<br />
return 0;<br />
}<br />
I know the main function didn't real work, but it is enough for a build, i think.
|
|
|
|
|
I also saw this in MSDN:
Library: Included as a resource in Activeds.dll.
GUID: IID_IADs is defined as FD8256D0-FD15-11CE-ABC4-02608C9E7553.
Which makes me think you need to import the ActiveDS.Dll into your project to get the interface library.
See about the #import directive:
The #import directive is used to incorporate information from a type library. The content of the type library is converted into C++ classes, mostly describing the COM interfaces.
|
|
|
|
|
That's right, i saw it to. And i tried it yesterday again, with normal '#import <activeds.dll>' (also with ") you get this error message:
--------------------Konfiguration: Test5 - Win32 Debug--------------------<br />
Kompilierung läuft...<br />
Test5.cpp<br />
d:\daten\projekte\teamscrip\c++\test5\test5.cpp(4) : fatal error C1083: Typbibliothek-Datei kann nicht geöffnet werden: 'activeds.dll': Fehler beim Laden der Typbibliothek/DLL.<br />
Fehler beim Ausführen von cl.exe.<br />
<br />
Test5.exe - 1 Fehler, 0 Warnung(en)<br />
the compiler wasn't able to load the dll.
|
|
|
|
|
I am really out of ideas, so anything at this point is going to be trial and error
MS says the 'interface library' is embedded within the DLL. Normally you would use the #import directive to get at that, and it does not currently work ...
Perhaps, try running RegServer on the Dll and see if it will show up as an ActiveX or else at least allow you to #import after doing that. Maybe it is not 'registered' yet?
Maybe there needs to be a TLB generation run against the DLL so you can include the type library in your project instead of importing the DLL directly.
Another thing I found on MDSN was this - (assume it is an ActiveX control for a moment..)
The following procedure adds dispatch class and header files for an ActiveX control to a Visual C++ project.
To add an ActiveX control to a Visual C++ Project:
On the Project menu, click Add to Project. A shortcut menu appears.
Click Components and Controls. The Components and Controls Gallery dialog box appears.
Click the component to add to your project. Visual C++ displays a dialog box from which you can select a subset of the component's classes to add to your project.
Click to select the check boxes of the classes you want to add, and click OK.
Visual C++ generates dispatch class and header files for the component and adds them to your project.
|
|
|
|
|
Okay, I think I got it...
1. Go to the stdafx.h and REMOVE the following line:
<br />
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers<br />
Once I did this, I did not get the error from the IAds.H header file complaining about the typedef interface lines of code any more. Must be using 'rarely used stuff'...
2. I included these header files:
<br />
#include "WTYPES.H"
#include "ADSIID.H"
#include "iads.h"
#include "Adshlp.h"
3. I added these libraries on the Project Settings : Link : Input : Object/Library Modules :
ActiveDS.lib adsiid.lib
Then I was able to compile and link a project with these lines in it:
<br />
HRESULT hr;<br />
IADs* pads;<br />
hr = ADsGetObject( L"LDAP://rootDSE", IID_IADs, (void**)&pads);<br />
Note that you had IADS and I changed it to IADs
|
|
|
|
|
I tried it and becomes this:
--------------------Konfiguration: Test5 - Win32 Debug--------------------<br />
Kompilierung läuft...<br />
StdAfx.cpp<br />
Kompilierung läuft...<br />
Test5.cpp<br />
d:\program files\microsoft visual studio\vc98\include\iads.h(3346) : error C2283: 'get_DefaultContainer' : Rein virtuelle Methoden sind in unbenannter Klasse/Struktur struct nicht erlaubt<br />
d:\program files\microsoft visual studio\vc98\include\iads.h(3349) : error C2283: 'put_DefaultContainer' : Rein virtuelle Methoden sind in unbenannter Klasse/Struktur struct nicht erlaubt<br />
d:\program files\microsoft visual studio\vc98\include\iads.h(3351) : error C2627: '<unbekannt>' : Member-Funktion in einer unbenannten Klasse definiert<br />
d:\program files\microsoft visual studio\vc98\include\iads.h(3351) : warning C4094: Unbenanntes 'struct' deklariert keine Symbole<br />
<br />
Test5.exe - 3 Fehler, 1 Warnung(en)
After this i set a preprozessor definition "CINTERFACE" to use the standard C interface and my compile works. Now i will try to get the information from LDAP. If you knew something about this errors, please tell me.
Otherwise i will try it with the work around.
Thank you
Carl
|
|
|
|