Connect two third party modules with “const char*” and “char*” argumentsHow to convert a std::string to const char* or char*?Convert const char* type to int arrayWhat is the difference between using Str.c_str() directly and use it to initialize a const char *?static_cast from 'const unsigned char *const *' to 'const char *const *' is not allowedVC++ cannot convert argument from 'CString' to 'const char *'Correct use of PlaySound function in C++Efficient way to pass expressions of local variables to third party library (Ipopt)Cannot initialize const int from unpacked tupleWriting to an Output FileFunction receiving a const struct and cin commend

Why is consensus so controversial in Britain?

How can saying a song's name be a copyright violation?

Neighboring nodes in the network

What to put in ESTA if staying in US for a few days before going on to Canada

Does a druid starting with a bow start with no arrows?

How to take photos in burst mode, without vibration?

Where does SFDX store details about scratch orgs?

What's the point of deactivating Num Lock on login screens?

What do you call someone who asks many questions?

What does it mean to describe someone as a butt steak?

In a Spin are Both Wings Stalled?

Arrow those variables!

Is "remove commented out code" correct English?

Watching something be written to a file live with tail

Twin primes whose sum is a cube

Stopping power of mountain vs road bike

Forgetting the musical notes while performing in concert

Were any external disk drives stacked vertically?

If human space travel is limited by the G force vulnerability, is there a way to counter G forces?

Would Slavery Reparations be considered Bills of Attainder and hence Illegal?

Anagram holiday

I Accidentally Deleted a Stock Terminal Theme

Blender 2.8 I can't see vertices, edges or faces in edit mode

Could gravitational lensing be used to protect a spaceship from a laser?



Connect two third party modules with “const char*” and “char*” arguments


How to convert a std::string to const char* or char*?Convert const char* type to int arrayWhat is the difference between using Str.c_str() directly and use it to initialize a const char *?static_cast from 'const unsigned char *const *' to 'const char *const *' is not allowedVC++ cannot convert argument from 'CString' to 'const char *'Correct use of PlaySound function in C++Efficient way to pass expressions of local variables to third party library (Ipopt)Cannot initialize const int from unpacked tupleWriting to an Output FileFunction receiving a const struct and cin commend






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








7















I have two third party modules and I have to combine them.
First I get data from a class. I will submit this data to a function.



bool loadLibrary(const char *strPlugName)
HPLUGIN temp = _BASS_PluginLoad(strPlugName,0);
return false;



The const char * strPlugName is a value that I got from another library. I cannot change this value type myself.



Inside the function I try to call a BASS Library function.



HPLUGIN temp = _BASS_PluginLoad(strPlugName,0);
Definition: typedef HPLUGIN (*BASS_PluginLoad_Type)(char *file,DWORD flags);


Here Xcode tell me:



Cannot initialize a parameter of type 'char *' with an rvalue of type 'const char *'


My question is how I can convert or cast this const char * to char *?










share|improve this question









New contributor




Thomas D is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Not to get crucified, but const_cast ... ouch...

    – user1810087
    2 days ago

















7















I have two third party modules and I have to combine them.
First I get data from a class. I will submit this data to a function.



bool loadLibrary(const char *strPlugName)
HPLUGIN temp = _BASS_PluginLoad(strPlugName,0);
return false;



The const char * strPlugName is a value that I got from another library. I cannot change this value type myself.



Inside the function I try to call a BASS Library function.



HPLUGIN temp = _BASS_PluginLoad(strPlugName,0);
Definition: typedef HPLUGIN (*BASS_PluginLoad_Type)(char *file,DWORD flags);


Here Xcode tell me:



Cannot initialize a parameter of type 'char *' with an rvalue of type 'const char *'


My question is how I can convert or cast this const char * to char *?










share|improve this question









New contributor




Thomas D is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Not to get crucified, but const_cast ... ouch...

    – user1810087
    2 days ago













7












7








7








I have two third party modules and I have to combine them.
First I get data from a class. I will submit this data to a function.



bool loadLibrary(const char *strPlugName)
HPLUGIN temp = _BASS_PluginLoad(strPlugName,0);
return false;



The const char * strPlugName is a value that I got from another library. I cannot change this value type myself.



Inside the function I try to call a BASS Library function.



HPLUGIN temp = _BASS_PluginLoad(strPlugName,0);
Definition: typedef HPLUGIN (*BASS_PluginLoad_Type)(char *file,DWORD flags);


Here Xcode tell me:



Cannot initialize a parameter of type 'char *' with an rvalue of type 'const char *'


My question is how I can convert or cast this const char * to char *?










share|improve this question









New contributor




Thomas D is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I have two third party modules and I have to combine them.
First I get data from a class. I will submit this data to a function.



bool loadLibrary(const char *strPlugName)
HPLUGIN temp = _BASS_PluginLoad(strPlugName,0);
return false;



The const char * strPlugName is a value that I got from another library. I cannot change this value type myself.



Inside the function I try to call a BASS Library function.



HPLUGIN temp = _BASS_PluginLoad(strPlugName,0);
Definition: typedef HPLUGIN (*BASS_PluginLoad_Type)(char *file,DWORD flags);


Here Xcode tell me:



Cannot initialize a parameter of type 'char *' with an rvalue of type 'const char *'


My question is how I can convert or cast this const char * to char *?







c++






share|improve this question









New contributor




Thomas D is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Thomas D is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









StoryTeller

104k13219282




104k13219282






New contributor




Thomas D is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Thomas DThomas D

445




445




New contributor




Thomas D is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Thomas D is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Thomas D is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Not to get crucified, but const_cast ... ouch...

    – user1810087
    2 days ago

















  • Not to get crucified, but const_cast ... ouch...

    – user1810087
    2 days ago
















Not to get crucified, but const_cast ... ouch...

– user1810087
2 days ago





Not to get crucified, but const_cast ... ouch...

– user1810087
2 days ago












2 Answers
2






active

oldest

votes


















12














If and only if the function called via _BASS_PluginLoad doesn't alter the memory pointed at by file, you can use a const_cast:



HPLUGIN temp = _BASS_PluginLoad(const_cast<char*>(strPlugName),0);


Some old c API's are not const correct on account of the const keyword being a fairly late addition to the C language. But they still don't mutate their arguments, so a const_cast is the easiest way to make use of them in const correct C++ wrappers. It's a perfectly legitimate reason (maybe even the reason) for that cast.






share|improve this answer




















  • 1





    Note that only some APIs can be fixed like this. Others actually do temporarily mutate their argument. (There's a notorious Win32 API which does this, but I can't remember which it is.)

    – Martin Bonner
    2 days ago


















6














The easy and safe way is to copy the argument into a local buffer, and then pass a pointer to that. As you are using C++, you can automate the memory management.



bool loadLibrary(const char *strPlugName)
std::string local(strPlugName);
local.push_back(''); // Ensure null terminated, if not using C++11 or greater
HPLUGIN temp = _BASS_PluginLoad(&local[0],0);
return false;



If using C++17, you can just call local.data() instead of &local[0].



Language lawyer caveat:



Strictly speaking, &local[0] was not defined to work in C++98 - in practice it always did (and later versions of the standard defined it to work).






share|improve this answer

























  • You can skip the null termination since C++11 if memory serves. You do need C++17 for the const correct local.data() however.

    – StoryTeller
    2 days ago











  • @StoryTeller local.data() is null-terminated in C++11, but I'm not sure &local[0] is - BICBW.

    – Martin Bonner
    2 days ago











  • They both produce the same buffer (as does c_str) since C++11. The null terminator is guaranteed.

    – StoryTeller
    2 days ago











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






Thomas D is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55468898%2fconnect-two-third-party-modules-with-const-char-and-char-arguments%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









12














If and only if the function called via _BASS_PluginLoad doesn't alter the memory pointed at by file, you can use a const_cast:



HPLUGIN temp = _BASS_PluginLoad(const_cast<char*>(strPlugName),0);


Some old c API's are not const correct on account of the const keyword being a fairly late addition to the C language. But they still don't mutate their arguments, so a const_cast is the easiest way to make use of them in const correct C++ wrappers. It's a perfectly legitimate reason (maybe even the reason) for that cast.






share|improve this answer




















  • 1





    Note that only some APIs can be fixed like this. Others actually do temporarily mutate their argument. (There's a notorious Win32 API which does this, but I can't remember which it is.)

    – Martin Bonner
    2 days ago















12














If and only if the function called via _BASS_PluginLoad doesn't alter the memory pointed at by file, you can use a const_cast:



HPLUGIN temp = _BASS_PluginLoad(const_cast<char*>(strPlugName),0);


Some old c API's are not const correct on account of the const keyword being a fairly late addition to the C language. But they still don't mutate their arguments, so a const_cast is the easiest way to make use of them in const correct C++ wrappers. It's a perfectly legitimate reason (maybe even the reason) for that cast.






share|improve this answer




















  • 1





    Note that only some APIs can be fixed like this. Others actually do temporarily mutate their argument. (There's a notorious Win32 API which does this, but I can't remember which it is.)

    – Martin Bonner
    2 days ago













12












12








12







If and only if the function called via _BASS_PluginLoad doesn't alter the memory pointed at by file, you can use a const_cast:



HPLUGIN temp = _BASS_PluginLoad(const_cast<char*>(strPlugName),0);


Some old c API's are not const correct on account of the const keyword being a fairly late addition to the C language. But they still don't mutate their arguments, so a const_cast is the easiest way to make use of them in const correct C++ wrappers. It's a perfectly legitimate reason (maybe even the reason) for that cast.






share|improve this answer















If and only if the function called via _BASS_PluginLoad doesn't alter the memory pointed at by file, you can use a const_cast:



HPLUGIN temp = _BASS_PluginLoad(const_cast<char*>(strPlugName),0);


Some old c API's are not const correct on account of the const keyword being a fairly late addition to the C language. But they still don't mutate their arguments, so a const_cast is the easiest way to make use of them in const correct C++ wrappers. It's a perfectly legitimate reason (maybe even the reason) for that cast.







share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago

























answered 2 days ago









StoryTellerStoryTeller

104k13219282




104k13219282







  • 1





    Note that only some APIs can be fixed like this. Others actually do temporarily mutate their argument. (There's a notorious Win32 API which does this, but I can't remember which it is.)

    – Martin Bonner
    2 days ago












  • 1





    Note that only some APIs can be fixed like this. Others actually do temporarily mutate their argument. (There's a notorious Win32 API which does this, but I can't remember which it is.)

    – Martin Bonner
    2 days ago







1




1





Note that only some APIs can be fixed like this. Others actually do temporarily mutate their argument. (There's a notorious Win32 API which does this, but I can't remember which it is.)

– Martin Bonner
2 days ago





Note that only some APIs can be fixed like this. Others actually do temporarily mutate their argument. (There's a notorious Win32 API which does this, but I can't remember which it is.)

– Martin Bonner
2 days ago













6














The easy and safe way is to copy the argument into a local buffer, and then pass a pointer to that. As you are using C++, you can automate the memory management.



bool loadLibrary(const char *strPlugName)
std::string local(strPlugName);
local.push_back(''); // Ensure null terminated, if not using C++11 or greater
HPLUGIN temp = _BASS_PluginLoad(&local[0],0);
return false;



If using C++17, you can just call local.data() instead of &local[0].



Language lawyer caveat:



Strictly speaking, &local[0] was not defined to work in C++98 - in practice it always did (and later versions of the standard defined it to work).






share|improve this answer

























  • You can skip the null termination since C++11 if memory serves. You do need C++17 for the const correct local.data() however.

    – StoryTeller
    2 days ago











  • @StoryTeller local.data() is null-terminated in C++11, but I'm not sure &local[0] is - BICBW.

    – Martin Bonner
    2 days ago











  • They both produce the same buffer (as does c_str) since C++11. The null terminator is guaranteed.

    – StoryTeller
    2 days ago















6














The easy and safe way is to copy the argument into a local buffer, and then pass a pointer to that. As you are using C++, you can automate the memory management.



bool loadLibrary(const char *strPlugName)
std::string local(strPlugName);
local.push_back(''); // Ensure null terminated, if not using C++11 or greater
HPLUGIN temp = _BASS_PluginLoad(&local[0],0);
return false;



If using C++17, you can just call local.data() instead of &local[0].



Language lawyer caveat:



Strictly speaking, &local[0] was not defined to work in C++98 - in practice it always did (and later versions of the standard defined it to work).






share|improve this answer

























  • You can skip the null termination since C++11 if memory serves. You do need C++17 for the const correct local.data() however.

    – StoryTeller
    2 days ago











  • @StoryTeller local.data() is null-terminated in C++11, but I'm not sure &local[0] is - BICBW.

    – Martin Bonner
    2 days ago











  • They both produce the same buffer (as does c_str) since C++11. The null terminator is guaranteed.

    – StoryTeller
    2 days ago













6












6








6







The easy and safe way is to copy the argument into a local buffer, and then pass a pointer to that. As you are using C++, you can automate the memory management.



bool loadLibrary(const char *strPlugName)
std::string local(strPlugName);
local.push_back(''); // Ensure null terminated, if not using C++11 or greater
HPLUGIN temp = _BASS_PluginLoad(&local[0],0);
return false;



If using C++17, you can just call local.data() instead of &local[0].



Language lawyer caveat:



Strictly speaking, &local[0] was not defined to work in C++98 - in practice it always did (and later versions of the standard defined it to work).






share|improve this answer















The easy and safe way is to copy the argument into a local buffer, and then pass a pointer to that. As you are using C++, you can automate the memory management.



bool loadLibrary(const char *strPlugName)
std::string local(strPlugName);
local.push_back(''); // Ensure null terminated, if not using C++11 or greater
HPLUGIN temp = _BASS_PluginLoad(&local[0],0);
return false;



If using C++17, you can just call local.data() instead of &local[0].



Language lawyer caveat:



Strictly speaking, &local[0] was not defined to work in C++98 - in practice it always did (and later versions of the standard defined it to work).







share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago









Toby Speight

17.4k134368




17.4k134368










answered 2 days ago









Martin BonnerMartin Bonner

23.8k33267




23.8k33267












  • You can skip the null termination since C++11 if memory serves. You do need C++17 for the const correct local.data() however.

    – StoryTeller
    2 days ago











  • @StoryTeller local.data() is null-terminated in C++11, but I'm not sure &local[0] is - BICBW.

    – Martin Bonner
    2 days ago











  • They both produce the same buffer (as does c_str) since C++11. The null terminator is guaranteed.

    – StoryTeller
    2 days ago

















  • You can skip the null termination since C++11 if memory serves. You do need C++17 for the const correct local.data() however.

    – StoryTeller
    2 days ago











  • @StoryTeller local.data() is null-terminated in C++11, but I'm not sure &local[0] is - BICBW.

    – Martin Bonner
    2 days ago











  • They both produce the same buffer (as does c_str) since C++11. The null terminator is guaranteed.

    – StoryTeller
    2 days ago
















You can skip the null termination since C++11 if memory serves. You do need C++17 for the const correct local.data() however.

– StoryTeller
2 days ago





You can skip the null termination since C++11 if memory serves. You do need C++17 for the const correct local.data() however.

– StoryTeller
2 days ago













@StoryTeller local.data() is null-terminated in C++11, but I'm not sure &local[0] is - BICBW.

– Martin Bonner
2 days ago





@StoryTeller local.data() is null-terminated in C++11, but I'm not sure &local[0] is - BICBW.

– Martin Bonner
2 days ago













They both produce the same buffer (as does c_str) since C++11. The null terminator is guaranteed.

– StoryTeller
2 days ago





They both produce the same buffer (as does c_str) since C++11. The null terminator is guaranteed.

– StoryTeller
2 days ago










Thomas D is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















Thomas D is a new contributor. Be nice, and check out our Code of Conduct.












Thomas D is a new contributor. Be nice, and check out our Code of Conduct.











Thomas D is a new contributor. Be nice, and check out our Code of Conduct.














Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55468898%2fconnect-two-third-party-modules-with-const-char-and-char-arguments%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.