|
try this:
void Arr(CString pArray[], int intArrCount)
{
for(int i=0; i<intArrCount; i++)
pArray[i] = "abc";
}
you simply pass the array like that:
CString array[4];
Arr(array, 4);
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Exactly the info I needed. Many many thanks!
Appreciate your help,
ns
|
|
|
|
|
I hope you are not writing software I will install for any reason on my computer in the future.
I am not bashing you, I am just figuring out you don't know what a pointer is. And it worries me.
sometimes it helps to look at the IL generated code
a MS guy on develop.com "answering" .NET issues
|
|
|
|
|
Well,
I am just trying to pattern it after a char array which we pass in by name as
myFunc(myArray)
where its
myFunc(char * myArray)
(Am I wrong about this too? )
Appreciate your help,
ns
|
|
|
|
|
ns wrote:
I am just trying to pattern it after a char array
Actually, you're better off using the MFC collection class CStringArray which seems ideally suited for your purpose, since you don't have to worry about freeing up storage, knowing its length, etc. Here's what I mean:
CStringArray arrayOfStrings;
for (long nIndex=0; (nIndex < 4); nIndex++) {
arrayOfStrings.Add ("abc");
}
myFunction (arrayOfStrings);
...
void myFunction
(CStringArray& stringArray)
{
}
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Then why don't you help the guy find out what a pointer is, instead of just telling him that he can't program?
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
I think there are a couple fundamental concepts you're missing here, so I'll try to explain it... hopefully this makes sense.
In a nutshell, your assignment of pArray[i] = "abc" fails because pArray isn't pointing at anything useful in your sample code. Your first line creates the pointer, but at that point it's merely a pointer to a CString; it's not really a CString yet.
A CString is an object, which is very different from the char data type. What's the difference between a CString pointer and a char pointer? You can do this with a char pointer:
char *c;
c = "abc";
When the compiler sees a literal string like "abc", it actually creates that string as a globally-accessible char array variable, which can then be "pointed at". This happens automatically for you, and you're not even really aware that it's happening. The char pointer in the above example can then point at that global variable because the datatypes match. It's a character array located at some address in memory, and you've got a character pointer that can store that address. Essentially, the above code is equivalent to doing this:
char cArray[4];
char *c;
cArray[0] = 'a';
cArray[1] = 'b';
cArray[2] = 'c';
cArray[3] = 0;
c = cArray;
Obviously this is a pain in the ass to code, so conveniently C and C++ compilers handle character strings automatically for you.
Okay, so now where does your CString come in? A CString is a C++ class that wraps character arrays; by itself it's not actually an array of characters. It's not a primitive datatype like char or int. If you tried the following, you'd get a compiler error:
CString *p;
p = "abc";
In this case, p is supposed to be pointing to a CString. "abc" as you learned is actually an array of characters, exactly 4 bytes long. You can't convert from an array of characters to a CString pointer; they're incompatible. You need to point at an actual CString object.
Knowing that, why does your code compile? Your code compiles fine because you access the pArray pointer through the reference operator []. This special operator lets you treat the pointer as a sort of index into an array. You can move anywhere within the array by just changing the index. However, there's a problem in your example. Your pArray isn't pointing at anything. You never initialized pArray to point to an array of CString objects. pArray is pointing at some garbage value off in no-man's land in memory. pArray[i] is trying to move around in that range, and it throws an access violation.
So, the bottom line is you need to initialize your pArray variable to actually point at some valid location in memory. You can follow some of the other examples, or even do something like this:
int iArraySize = 4;
CString *pArray = new CString[iArraySize];
for( int i = 0; i < iArraySize; i++ )
{
pArray[i] = "abc";
}
delete []pArray;
In this case, pArray points to an array of CString objects, dynamically allocated on the heap. The pointer can access each of the four through the reference operator.
Ty
"The significant problems we face cannot be solved at the same level of thinking we were at when we created them." -Albert Einstein
|
|
|
|
|
Many thanks. That really cleared up things for me.
Appreciate your help,
ns
|
|
|
|
|
I'm worried, this is commercial s/w you're developing?
Developing with C++ is like programming by the seat of your pants
|
|
|
|
|
How do you make a number (integer) into a CString?
Appreciate your help,
ns
|
|
|
|
|
CString str;
str.Format("%i", iFoo);
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thank you. Any thoughts on my CString * pArray thread? Its quite short and probably obvious to you...
Appreciate your help,
ns
|
|
|
|
|
I wish to make a SDI CFrameWnd based app appear like a dialog based app. Yea, I know I can create a dialog based app but for reasons I won't go into here, I don't want to go that route.
I used Spy++ to look at the style and dwStyleEx bits a a CFrameWnd and a dialog based app, and I've overloaded CMainFrame::PreCreateWindow() and have fiddled with the style and dwStyleEx bits, but I've had no luck.
TIA,
JB
|
|
|
|
|
Anyone have any experience building an app that uses MFC Doc/View and has a look and feel similar to VC6 ? I am trying to modify some code that is based on Doc View. Currently the code has a primary document, which is basically a project, that holds classes, and diagrams. When you open a file or create a new project this is waht you create first. Then if you add a diagram, you can edit the diagram as a new document type. All of which leads to a lot of clutter of MDI windows.
What I would like is to modify it so that when you open a project the main view is housed not in a MDI frame, but in a toolbar like in VC6 (the "Workspace" toolbar). Then any diagrams opened can open up in an MDI frame. Further more, each new project opened up, would add itself to a list that you toggle back and forth between projects.
Is this feasible in DocView ? The reason I want to do this is because the original code is written in DocView and I wanted to reuse(not break) as much as possible.
Any suggestions would be greatly appreciated !
|
|
|
|
|
If I understand what you want correctly, you might want to check out Cristi Posea's docking bars (nw). I've used them in a program to put a tree control that is actually a CView of the document beside the main view. The tree lists items in the project and allows you to select items into the main view.
people are not very wise / don't know their limitations /
don't know what death means / when they play their dirty games 'Killing Fields' Funker Vogt
|
|
|
|
|
Hi. I have been asked to develop my first telephony application. I think I want to do it with Visual C++ or Visual Basic.NET. The application: A program that will let the user dial in to his/her voice mail and access all of the features of the voice mail throught the computer. Does anyone know of existing libraries that might be helpful? Do we need a special modem? Does anyone know if it might be easier to implement in another language?
|
|
|
|
|
If you are using a modem, then TAPI is probably your best option - but a lot depends on the quality of TAPI support in your modem.
If you are going the TAPI route, the best language to use is C++. If you can limit your users to Win2k or XP then use TAPI 3. (You should also be able to use this VB)
If you need to support 9x then you will have to use TAPI 2, so then C++ is about your best option.
See my message here for further links,
http://www.codeproject.com/useritems/tapi.asp?msg=297243#xx297243xx[^]
Michael
"Time and tide melts the snowman."
-- The Doctor (Doctor Who: Time and the Rani
|
|
|
|
|
Michael P Butler wrote:
If you can limit your users to Win2k or XP then use TAPI 3. (You should also be able to use this VB)
I haven't seen any TAPI drivers that supports TAPI 3.0 yet...
And you are right about the VB part, TAPI 3 is COM based, and can probably be used from any COM cabable language...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Anders Molin wrote:
I haven't seen any TAPI drivers that supports TAPI 3.0 yet...
In theory all existing TAPI 2.x TSPI should be useable for TAPI 3. TAPI 3 is basically a COM wrapper around TAPI 2. All the TAPI 2 drivers I've used have supported TAPI 3 - even those that were developed by TAPI 3 was completed.
Michael
"I've died for a living in the movies and tv.
But the hardest thing I'll ever do is watch my leading ladies,
Kiss some other guy while I'm bandaging my knee."
-- The Unknown Stuntman
|
|
|
|
|
Michael P Butler wrote:
All the TAPI 2 drivers I've used have supported TAPI 3
Nice, I did not know that, I thought that they have to be writtten for TAPI 3.
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
I vould definitely go for VC. You cannot use TAPI older than version 3.0 from VB.
If you want to use a modem to make the calls the the voice mail system, make sure there are some (good) TAPI drivers for that modem.
Make sure the TAPI drivers supports the lineGenerateDigits() function, because you'r gonna use that function to send DTMF tones to the voicemail system...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Thanks for the help everyone! I guess the hard part is learning what functions are available in TAPI and whether or not my drivers support it. Does anyone know of a good reference book or website that would list the functions that TAPI provides?
|
|
|
|
|
IS there such a thing as ( CString *p , SizeOfArray)) when I'm passing in a CString array? I havent seeen CSTring pointers so I was wondering....
Appreciate your help,
ns
|
|
|
|
|
perhaps you should use
CStringArray m_pszMyString
m_pszMyString.Add("1");
m_pszMyString.Add("2");
m_pszMyString.Add("3");
if(m_pszMyString.GetAt(0) == "1")
{
..
bla
}
hope it helps
for people who think life is like a comedy
for people who feel is a tragedy
Whapole
|
|
|
|
|
helps! GetAt() was is new to me, so great to know it.
Appreciate your help,
ns
|
|
|
|