|
Hi,
I have an array like this :
char sArray[4][5];
I want to declare this array with new or malloc like this :
char** sArray=NULL;<br />
sArray = new char[20];<br />
or sArray = (char*)malloc(20);
Can anybody help me to write correct declaration
Thanks in advance
|
|
|
|
|
there is no simple way to do it in C++.
you will have to do something like this:
int ** array = new int* [sizex];
for (int i = 0; i < sizex; ++i)
array[i] = new int[sizez];
-c
"Half of the harm that is done in this world is due to people who want to feel important."
-- TS Elliot
|
|
|
|
|
Hi,
I've made a bad choice in implementing the icon retrieving code in my code. But's hardcoded now and would be toough and bug producing to make any really major corrections now.
So anyway, the question: I need to get the icon of some file (SHGetFileInfo), but with shortcut overlay (or shared overlay, but this is not neccessary), for both 16x16 and 32x32 icons. In other words, a image list that would contain both "shortcuted" and standard icons.
Thanks in advance
|
|
|
|
|
|
Hello there,
How can i convert my Unicode string to Arabic 1256 codepage ?
Arabic 1256 is ANSI ???
I mean for solving my problem i must convert Unicode characters to ANSI ??
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Hi All,
I've been having weird heap breakpoints show up in an app that is using the winsock 2 library, and have heard that this may be related to the version of the C runtime libraries I am linking with. Anybody know which version is the corrcet one to use with the winsock libraries? Multithreaded, Single Threaded, Multithreaded .dll?
Thanks
Aaron
|
|
|
|
|
My VB function signature is:
Public Function MakeDB(txtFilename As String, dataBaseName As String)
I will pass these two parameters from VC as:
CString dbName, myFile;
edit1.GetWindowText(dbName);
edit2.GetWindowText(myFile);
ptr->MakeDB(myFile, dbName)
What I need to know is can I do this or do CStrings and VB strings differ. if so, how to pass these strings to the VB dll?
Thanks,
ns
|
|
|
|
|
Well, I did what I said above, and got the VC compile error:
C:\msway\mswayView.cpp(174) : error C2664: 'MakeDB' : cannot convert parameter 1 from 'class CString' to 'unsigned short ** '
with:
ptr.CreateInstance(__uuidof(Class1));
ptr->MakeDB(strFile,dataBaseName);
on the VC side
and
Public Function MakeDB(txtPMAFilename As String, dataBaseName As String)
on the VB side.
Help!!
Thanks,
ns
(ps. I am going to convert my CStrings into char * but dont know if that will do it...)
|
|
|
|
|
Nope. this time with char* passed into VB, I got the compile error in VC:
C:\Trainer\A_TR NOBlob inDB series\VBDBDll2\msway\mswayView.cpp(185) : error C2664: 'MakeDB' : cannot convert parameter 1 from 'char *' to 'unsigned short ** '
Now what to try?
Thanks,
ns
|
|
|
|
|
The short answer:place a call to SysAllocString around your char*.
The longer one: Strings in COM are not 'char*' , but 'BSTR', which is a length-prefixed, wide-character string. Furthermore, allocation of these BSTR must be handled by the COM runtime, you are not allowed to do it yourself. SysAllocString() allocates a block of memory to hold the string you passed it, converted to a widestring and returns a pointer to this memory-block. You can use that pointer as an argument in your method-call.
When your finished with the BSTR, you should call SysFreeString() on it.
If you're going to use COM from C++, you will save yourself a lot of trouble by reading some initiating articles, like Beginner's Tutorial: Calling Visual Basic ActiveX DLLs from Visual C++ here at The Code Project.
|
|
|
|
|
Thanks. I was following the article from CP and got MIDL compiler errors so gave up. I see that hes just passing a _bstr_t. I'll have to convert the GetWindowText(pathName) to a _bstr_t. You say that allocation has to be done by the COM runtime, yet the article just passes in a _bstr_t. I'm probably missing something here. Thanks very much for the response. I get to try it tomorrow.
|
|
|
|
|
_bstr_t, just like CComBSTR mentioned in another reply, is a wrapper object around BSTR that handles allocation and destruction transparently. In other words, you can use without knowing the details.
|
|
|
|
|
I tried your method and still got the compile error:
C:\msway\mswayView.cpp(169) : error C2664: 'SysAllocString' : cannot convert parameter 1 from 'char *' to 'const unsigned short *'
My VB dll function that I'm passing to has the signature:
Public Function MakeDB(txtPMAFilename As String, dataBaseName As String)
and I just tried:
CString dataBaseName0 = "C:\\Image.mdb";
CString strFile0 = "C:\\Trainer\\final1.txt";
char* dataBaseName = new char[dataBaseName0.GetLength() +1];
strcpy(dataBaseName, dataBaseName0);
<code>_bstr_t b_dataBaseName = SysAllocString (dataBaseName);</code>
char* strFile = new char[strFile0.GetLength() +1];
strcpy(strFile, strFile0);
<code> _bstr_t b_strFile = SysAllocString (strFile);</code>
_Class1Ptr ptr;
ptr.CreateInstance(__uuidof(Class1));
<code>ptr->MakeDB( b_strFile, b_dataBaseName);</code>
SysFreeString (b_dataBaseName);
SysFreeString (b_strFile);
|
|
|
|
|
This is all you'll be needing:
_bstr_t b_dataBaseName = "C:\\Image.mdb";
_bstr_t b_strFile = "C:\\Trainer\\final1.txt";
_Class1Ptr ptr;
ptr.CreateInstance(__uuidof(Class1));
ptr->MakeDB( b_strFile, b_dataBaseName);
I have given the impression that it was SysAllocString takes a char* and converts it to a widestring. That is not true. Sorry for that.
In the above code, the _bstr_t does all the work for you:
- it converts the char* to wchar_t*
- it makes calls to SysAllocString() and SysFreeString() when needed
So there's no need to make calls to SysAllocString yourself when using a _bstr_t.
|
|
|
|
|
Great! Thanks. Now the only remaining thing to iron out in this issue is that the VB dll functions argument had to be changed to MyFunc(ByVal as String) or it wouldnt compile. This seems to indicate that I cant pass in a _bstr_t that I want modified by the dll and have the changes persist in the VC - I mean by passing in the _bstr_t by reference. Like if I wanted the VB dll to fill in myBstrString, I'd call it like:
ptr->FillString(&myBstrString) pls correct me here if I am wrong in calling it like this to get what I want
and in the VB dll
Function FillString(ByRef a as String)
a ="filledByVB"
I'd really appreciate if you can let me know if I'm understanding this pass by reference notion correctly (esp on the VC side - maybe I dont need that & in the ptr call, do I? If the argument was an int or something, I know for sure we'd need to pass in &myInt, and the & would be necessary )
Anyways the time the compiler was unhappy was when the dl had ByRef and I sent in the _bstr_t like this:
ptr->FillString( myBstrString);
Thanks,
ns
|
|
|
|
|
VB uses BSTRs I believe, so use temporary CComBSTR variables in your call:
ptr->MakeDB ( CComBSTR(LPCTSTR(myFile)), CComBSTR(LPCTSTR(dbName)) );
--Mike--
Just released - RightClick-Encrypt v1.4 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
That looks like a cool solution. MAny many thanks.
|
|
|
|
|
Unfortunately the compiler didnt like the CComBSTR either...
Thanks anyways.
ns
|
|
|
|
|
Hi,
I've been programming in VC++ for a while now and I'm pretty good at it, but I've only been dealing with the coding aspect C++. Now I want to make a GUI front end for the programs I wrote. Where can I learn about making a GUI front end for VC++? Is there a place where I can download really simple sample code and programs? Thanks in Advance
|
|
|
|
|
WhiteLegend wrote:
Is there a place where I can download really simple sample code and programs?
Um... yes, it's called CodeProject.
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
yeah ravs right.. there are tutorials located right here at codeproject..
xai
|
|
|
|
|
I have a VB COM dll that I call from my MFC app with an #import statement, but its not known where the program wil be installed. If I get the appDir from the app, I cant really build a #import pathName + '\' + filename since this statement is outside the code. I suppose I could force the user to put the COM dll into one of the Program files subfolders (via the WISE installer), so is it safe to assume very windows user has this directory? Not everyone has a system32 folder - is that right?
How to safeguard against this: if the #import has a bad pathname (for whatever reason). What sort of errors does one get and whats a graceful exit?
Thanks,
ns
|
|
|
|
|
#import is a compile-time thing, not runtime. Use the path to the file on your machine.
--Mike--
Just released - RightClick-Encrypt v1.4 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
I wont know where the user will install the app, so the dll cant be put in the app folder on the target machine. Thats why I'm wondering if I should install it in their system folder (since my com dll is not an ADO dll though it is database related...):
#import "c:\Program Files\Common Files\system\ado\msadox.dll" no_namespace
#import "c:\Program Files\Common Files\system\myVBCOM.dll" no_namespace
I have control over where WISE installs the dll, but the user can choose his own directory for the app, so thats an unknown.
|
|
|
|
|
#import is compile-time. All that matters is where the DLL is on your machine. When your app creates the COM objects, the location of the DLLs doesn't matter because COM looks in the registry to get the file paths.
--Mike--
Just released - RightClick-Encrypt v1.4 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|