?
Solved

Passing info to a DLL

Posted on 2003-02-27
6
Medium Priority
?
164 Views
Last Modified: 2010-04-01
I'm attempting to write a DLL that I can call from another application that I use.  The functions in the DLL are relatively simple and I have managed to get them to work except for one thing.  

Here is the Function and parameters;
char* StripDuplicates(char* sFromAMS, int iCaseSensitive)
{
//my functions code here
}

My problem is that when a File and Pathname (i.e. C:\Music\test.mp3;;C:\Music\sample.mp3) are passed to the DLL, the function blows up because of the backslash.  Keep in mind that the function needs to pass the same string back after it has been sorted accordingly.  How do I work around this?
0
Comment
Question by:BWarmuskerken
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 2

Expert Comment

by:bkrahmer
ID: 8039285
Where are you getting the filenames from?  If you are coding them like this: char fname[] = { "c:\temp\foo" }, this will not work.  You need to add another slash to escape each slash, ala c:\\temp\\foo.
brian
0
 
LVL 1

Author Comment

by:BWarmuskerken
ID: 8039333
The filenames are being passed by the application calling the dll.  I'm using a Media Authoring program that allows you to call DLLs from within, passing it parameters.  In this case, the sFromAMS parameter would hold a delimited string such as "C:\temp\foo\1.mp3;;C:\temp\foo\2.mp3;;C:\temp\foo\3.mp3"

I then take this string, break it apart into an array, sort it, then reassemble the string with delimiters.

I'm aware that I need a double backslash (\\), but how do I change that in the passed parameter sFromAMS?

0
 
LVL 1

Author Comment

by:BWarmuskerken
ID: 8039351
The filenames are being passed by the application calling the dll.  I'm using a Media Authoring program that allows you to call DLLs from within, passing it parameters.  In this case, the sFromAMS parameter would hold a delimited string such as "C:\temp\foo\1.mp3;;C:\temp\foo\2.mp3;;C:\temp\foo\3.mp3"

I then take this string, break it apart into an array, sort it, then reassemble the string with delimiters.

I'm aware that I need a double backslash (\\), but how do I change that in the passed parameter sFromAMS?

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 6

Accepted Solution

by:
PlanetCpp earned 150 total points
ID: 8039562
i don't think that's your problem. the \\ is only for the compiler, the actual string shouldn't have \\ in it. the compiler sees \\ and changes it to \
if you got the path and filename from some function or if its being passed by a program then it's fine. i think your problem is somewhere else, you're returning a char*
this is generally not a good idea, is this how to media program wants it??
thing is when you make that string in the dll function and then pass the pointer to it back to the application, when that pointer gets back to the program it no longer exists. once the function ends the space is deallocated.
the string MIGHT still be there but only by chance that it hasnt been overwritten. ie.
char* myfunction()
{
char mystring[] = {"hello world"};
return mystring;
}
is no good.
once the fucntion ends the memory address that mystring is pointing to is deallocated.
if you HAVE to return that type becaus that media program is making yo, then you have to make the char array static
static char mystring[100] = {""}; for example
at least then the memory will not be on the local stack for that function and will be preserved but even then it's not good programming practice and im not sure if that pointer will work well from a dll to an app,off the top of my head i think it would since that dll will be loaded into your (the media programs) process space.
if you don't have to, then add another parameter for the char* and have the funtion return void or maybe a success/fail indicator. change the char* through a parameter, its safer
0
 
LVL 1

Author Comment

by:BWarmuskerken
ID: 8041601
I am extemely new to C++ and am easily confused by the whole pointer thing.  I'm sure that I don't have to have it be a pointer.  I thought that the char* meant it was an Array.  Eeeech!

Maybe I should drop back and do some more reading, before I waste to many peoples time.
   
0
 
LVL 1

Author Comment

by:BWarmuskerken
ID: 8061862
My lack of understanding the while pointer deal.  You were exactky right,  the string having a \ in it had nothing to do with my problem
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question