|
Hello,
How can I convert const char* to LPCTSTR?
I tried to use WideCharToMultiByte so that I could have a LPCWSTR then convert to LPCTSTR but
the value of LPCWSTR(pdbfilename) on watch during breakpoint at line 9 is "???". (see code below)
1 HANDLE
2 fCreate(const char *fname, UInt32 access, UInt32 shared, UInt32 create, UInt32 attrib, Err *r_)
3 {
4 Err r = errNone;
5 HANDLE handle = NULL;
6 LPSTR holder=(LPSTR)fname;
7 LPCWSTR pdbfilename;
8 WideCharToMultiByte(CP_OEMCP, WC_DEFAULTCHAR,pdbfilename, -1,holder,strlen(fname),NULL, NULL);
9 handle = CreateFile(pdbfilename, access, shared, NULL, create, attrib, NULL);
10 if(handle == INVALID_HANDLE_VALUE)
r = ERR_FILE_CREATEOPENFAILED;
11 if(r_ != NULL)
12 *r_ = r;
13 return handle;
14 }
Is there something wrong with my WideCharToMultiByte API call?
Is there other way to convert const char* to LPCTSTR?
Thanks and more power.
|
|
|
|
|
I thought LPCTSTR WAS a char * ? Anyhow, the easiest way to convert is to use the _bstr_t class, which is a string class that returns wide and narrow strings automagically.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi Christian,
Actually, the function belongs to a library and so the library is restricted to plain C so that it will be portable because I'am developing under Pocket PC environment.
Let me rephrase the question, on EVC4 LPCTSTR is unsigned short*, my first parameter (fname) is const char*, so how can i convert const char* to unsigned short*?
Thanks a lot Christian,
Fjlv2005
|
|
|
|
|
OK, if you want to do it in C, _bstr_t won't help, it's a class. However, it just calls the API function that you're trying to call now, anyhow. You could check it's source to see if it differs from your syntax.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Ok I'll just check the API.
Thanks and Have a nice day.
|
|
|
|
|
Have a look at the macros like A2CT, use MSDN "String Conversion Macros".
That was VC6, with VC7 their name has changed a bit (to A2CTEX or something).
----------------------
~hamster1
|
|
|
|
|
Hi everybody,
Since I have no experience in C++ I request your help. I created a C# app that will be installed from a CD-ROM; I used the .NET bootstrapper plug in to install the framework if it hasn't been installed yet.
I need to provide an autorun for the CD-ROM; but... the CD will not only be used for the installation of the program, but also for the normal use of the program. So I need the autorun to check whether the application has been installed, if not than run setup.exe; if yes, don't do any autorun.
Can somebody point me to some freeware program that does this for me, or to some other good resources (keeping in mind that I don't really know C++).
Thanks a lot.
Gidon
|
|
|
|
|
|
You can add to cd a file autorun.inf
file looks like:
[autorun]
open=edgeofchaos.exe
icon=edgeofchaos.exe,0
You can change, and you can try to write your ouwn program, to check if it is installed, if not then run setup.exe
or just use this autorun maker
http://www.indigorose.com/ams/index.php[^]
ps: Managed c++ has a little difrance than C#, if you program MC++ you can easly turn to C#
|
|
|
|
|
let's say i have a class like this:
class a
{
private:
char name[10];
.
.
.
}
how do i give 'name' a value in the constructor?
chen.
|
|
|
|
|
name = {"10 chars long"};
OR
name = new char[10];
::strcpy(&name[0], "value"); // going from memory, args could be the wrong way around
If you use the second method, don't forget to release memory in the destructor. If you use the first, don't change the value of the string, which means it should be const. Overall, you'd do better to use a string class to hold the value, if practical.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
If you get the name from the outside, go with this:
<br />
class a( const char* a_name) {<br />
strcpy(name,a_name);
}<br />
However, if you know the name at compile time already, simply hard-code it - gives more speed and security.
<br />
class a {<br />
const char* get_name() const { return "blabla"; }<br />
}<br />
----------------------
~hamster1
|
|
|
|
|
Instead of using a char array, consider a string class:
class a
{
private:
std::string name;
.
.
.
};
And then a constructor may look like:
a::a(const char* yourName) : name(yourName)
{}
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
-- modified at 8:32 Tuesday 30th August, 2005
|
|
|
|
|
There is a possible memory leak
<pre>private: System::Void btnButton_Click(System::Object *sender, System::EventArgs *e)
{
frmTest *frm = new frmTest(); // Create new Form
frm->ShowDialog(this); // Show
}</pre>
and i have defined destructor of that form
<pre>~frmTest
{
MessageBox::Show(S"Destructor Called");
}</pre>
When i run this app, i click button many times, and no destructor called. when i close main form, destructor is called only once.
so i have add:
<pre>delete frm; // To be safe.</pre>
is this a memory leak?
thanks in advance.
|
|
|
|
|
No, frm is created on managed heap, which is controlled by GC. In general, with managed code, you should worry more about leaking non-memory resources.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
Hai
In my applcation i want to list all machines in the network.
So i used the WNetOpenEnum API .
My code looks like,
[DllImport("Mpr.dll", EntryPoint="WNetOpenEnumA", CallingConvention=CallingConvention::Winapi)]
static ErrorCodes WNetOpenEnum(ResourceScope dwScope, ResourceType dwType, ResourceUsage dwUsage, NETRESOURCE* p, IntPtr &lphEnum);
NETRESOURCE* pRsrc = new NETRESOURCE(); //A managed class
IntPtr handle = IntPtr::Zero;
result = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK, RESOURCEUSAGE_ALL, pRsrc, handle);
But when i run the application got an error
" Can not marshal parameter #4: The type definition of this type has no layout information. "
Whats is the problem.
Plz help
|
|
|
|
|
Hello...
I believe you forget to define the StructLayoutAttribute for the paramater NETRESOURCE* p...
In general it'S Sequential...
|
|
|
|
|
Can somebodey point me to internet where can i find tutorial on multithreading. I prefear in MC++ but C# will do fine. I have found some tutorial, but i didn't see any sample, explenation on thread safe.
Thanks in advance
|
|
|
|
|
Hello,
I am trying to build a download accelarator (a program which downloads a file through several connections to increase the speed).
I have created four threads. Each thread downloads the file from diffrent offset and finallly I join al this parts.
The problem is that when I use one thread( without changing the thread's code) it much faster. It like the additional threads are slowing one another.
In each thread I initialize the connection (CInternetSession->CHttpSession) and later in the thread I have put a loop which downloads the files.
The initialization part is in a critical section.
Can anyone tell whats wrong. Did anyone encountered similar problem?
Sincerely yours
Y.R.
|
|
|
|
|
Hello All,
Does anybody know how to find out interfaces exposed by a driver (.sys file)?
Thanks in advance
|
|
|
|
|
I have App.exe which uses Dll.dll, I also add classical Microsoft manifest file App.manifest.exe to enable XP styles for common controls.
Now question how can I disable influence of manifest on Dll.dll
Which means I want that App.exe continue to use
comctl32.dll (ver 6) new one
but
Dll.dll should use
comctl32.dll (ver 5) old one
Load / Unload library - already try not helps
#define/#undefine IE_CONTLOLS - already try doesnt helps
I need to customize body of manifest somehow include or exclude styles in the dependency section
Thanks.
|
|
|
|
|
Hi,
I have created a test dll in Fortran that squares an input number.
Then I'm trying to call this dll from C++.NET using the following bit of code:
<br />
#include <iostream><br />
using namespace std;<br />
extern "C" __declspec(dllimport)double square(double X);<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
double a=4;<br />
double asq = square(a);<br />
cout << a << " " << asq << endl;<br />
return 0;<br />
}<br />
<code><br />
<br />
I get the following error:<br />
HelloWorld error LNK2019: unresolved external symbol __imp__square referenced in function _main<br />
<br />
I've added MyDll.lib as a reference from the Fortran code but no success. (I'm not able to add MyDll.dll however, is this normal?)<br />
Any ideas please?<br />
Kash
|
|
|
|
|
In the C++ .NET Framework you don't import functions from a DLL like you do in Win32; the syntax is different. The correct method is to use the DllImport attribute, which is located in: System::Runtime::InteropServices.
Using the DllImport Attribute[^]
|
|
|
|
|
Hi all,
I've created a form with a number of child windows. One certain window is behaving very strangely. If I open the child window and then close it, the main form will not close - by this I mean I can't click the exit button or use the exit menu item. The main reason for my confusion is that this behaviour only happens on certain machines.
Does anyone have any knowledge of why this might be occurring? It must have something to do with the individual machines but I can't find anything that would cause this and I was just wondering if any of you guys have come across this before.
Thanks in advance
Rich
|
|
|
|
|
I think there is a problem in your code. Try to debug, after you close certan window. Or try recreate this child window.
quote:
behaviour only happens on certain machines
If you use same setting for this child window then all child would have same problem
|
|
|
|