473,780 Members | 2,258 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot convert 'AnsiString' to 'const char *'

codexparse
1 New Member
I am writing a browser program in C++ Builder 6 that loads a web page using the following code:

Expand|Select|Wrap|Line Numbers
  1. void __fastcall TForm1::ToolButton1Click(TObject *Sender)
  2. {
  3.      wchar_t buff[100];
  4.      MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
  5.      "http://www.thescripts.com", -1, buff, sizeof(buff));
  6.      CppWebBrowser1->Navigate(buff, 0, 0, 0, 0);
  7. }
To include the address bar implementation, I need a temporary string derived from an edit box. This is the code I have tried but receive the error that I cannot convert an AnsiString to const char * and require a type conversion:

Expand|Select|Wrap|Line Numbers
  1. void __fastcall TForm1::ToolButton1Click(TObject *Sender)
  2. {
  3.      const char *tempstring = Edit1->Text;
  4.      wchar_t buff[100];
  5.      MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
  6.      tempstring, -1, buff, sizeof(buff));
  7.      CppWebBrowser1->Navigate(buff, 0, 0, 0, 0);
  8. }
I've tried to decipher how the TStringConverte r VCL class works but I have been unsuccesful determining how it works either:

TStringConverte r::AnsiToWide

Converts a null-terminated ANSI string to a wide (Unicode) string.
static LPWSTR AnsiToWide(LPCS TR src);

WideToAnsi calls MultiByteToWide Char(), using the ANSI code page, to convert the ANSI string specified by src to a null-terminated string of Unicode characters. The source string may be from a multibyte character set.

Thanks in advance for suggestions anyone might have as to how I can resolve this programming obstacle.
Nov 4 '07 #1
1 14975
Banfa
9,065 Recognized Expert Moderator Expert
instead of

Expand|Select|Wrap|Line Numbers
  1. const char *tempstring = Edit1->Text;
  2.  
try

Expand|Select|Wrap|Line Numbers
  1. const char *tempstring = Edit1->Text.c_str();
  2.  
Nov 5 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
21895
by: Mendon?a | last post by:
I cant seem to find on borland help files anything about AnsiString to char conversion. Just the opposite. Can u help me?
5
22056
by: Brad Moore | last post by:
Hey all, I'm getting the following compiler error from my code. I was wondering if anyone could help me understand the concept behind it (I actually did try and compile this degenerate example). int foo(const char* argv) { return 0; } int main(int argc, char* argv) {
2
11530
by: Abhijit Bhadra | last post by:
Hi , I was trying to build my project in VC with latest Service Packs but got this error . C:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE\atlconv.h(125) : error C2440: 'return' : cannot convert from 'const char *' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
6
16052
by: John Smith | last post by:
What's wrong with the use of atoi in the following code? Why do I get the error message: 'atoi' : cannot convert parameter 1 from 'char' to 'const char *' char cBuffer; void PushUnique(int); for(y = 0; y < 9; y++)
3
6290
by: Alfonso Morra | last post by:
Hi, I'm using a third party library which has a function that expects an arg of type const char*. I have a char* which is assigned a value at run time - how can I pass it to my function? Thanks
3
16828
by: kaizen | last post by:
Hi, i wrote the code in C and compiled in VC++ compiler. at that time it has thrown the below mentioned error. error C2664: 'strcpy' : cannot convert parameter 2 from 'char' to 'const char *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
3
13957
by: bg_ie | last post by:
Hi, I am using a API I downloaded from the internet programmed in C. I need the function below which works with this api in my c++ file - void StoreNoteCallback(void *context, int arglen, const void *args, OSCTimeTag when, NetworkReturnAddressPtr returnAddr) { const char *typeArgs = (const char *)args;
2
9155
by: nassim.bouayad.agha | last post by:
Hello, here is a code snippet showning my problem : template<typename _K> class TClass1 { public: void Process(const _K& arg) const {
5
5392
by: slizorn | last post by:
well the error i get is the title above: error C2664: 'searchTree' : cannot convert parameter 2 from 'const char *' to 'char' error is form this line searchTree(treeObj->root ,data1.c_str()); i have also attached searchTree below for yr reference
0
10306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9931
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6727
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.