Hi all,
Need a little help here.
I am trying to return the MAC of a codec using the following function but cant work out how to convert the Buffer from char[5] to char as the return value.
Error 5 error C2440: 'return' : cannot convert from 'char [5]' to 'char' j:\Indigo Vision\COM\VBserial.dll\IVserial.cpp 194
Its probably obvious but I can seem to convert it
Tim Norton -
char DisplayDeviceInfo( const VBDEVICEINFO *pDeviceInfo )
-
-
{
-
VBMSRV_PLAYBACKINFO pbInfo;
-
UINT nValue;
-
int nSize;
-
char Buffer[5];
-
-
sprintf(Buffer,
-
"%02X:%02X:%02X:%02X:%02X:%02X\n",
-
pDeviceInfo->macAddress.abMacAddr[ 0 ],
-
pDeviceInfo->macAddress.abMacAddr[ 1 ],
-
pDeviceInfo->macAddress.abMacAddr[ 2 ],
-
pDeviceInfo->macAddress.abMacAddr[ 3 ],
-
pDeviceInfo->macAddress.abMacAddr[ 4 ],
-
pDeviceInfo->macAddress.abMacAddr[ 5 ]
-
);
-
-
return Buffer;
-
}
-
5 2540
Your function is returning a char.
The name Buffer is a char*.
That's because the name of the array is the address of element 0.
You could change your function to return a char* but you would just crash again since you would return the address of a local variable.
The solution here is to have a char** argument and you allocate your Buffer on the heap using the char** argument: -
void DisplayDeviceInfo( const VBDEVICEINFO *pDeviceInfo, char** Buffer )
-
-
{
-
VBMSRV_PLAYBACKINFO pbInfo;
-
UINT nValue;
-
int nSize;
-
-
delete *Buffer; //delete the current Buffer
-
char* *Buffer = new char[5]; //allocate a new one
-
-
sprintf(*Buffer,
-
"%02X:%02X:%02X:%02X:%02X:%02X\n",
-
pDeviceInfo->macAddress.abMacAddr[ 0 ],
-
pDeviceInfo->macAddress.abMacAddr[ 1 ],
-
pDeviceInfo->macAddress.abMacAddr[ 2 ],
-
pDeviceInfo->macAddress.abMacAddr[ 3 ],
-
pDeviceInfo->macAddress.abMacAddr[ 4 ],
-
pDeviceInfo->macAddress.abMacAddr[ 5 ]
-
);
-
-
}
-
Thsnks for the response.
I will try that but there is something I iver looked mentioning that I think will impact on this.
I am creating a DLL that is returning the value to VB,
how do I get the charr** to output from the DLL?
May other public Functins all look like this
[code]ccp[
int __stdcall VbCleanup1()
bool __stdcall VbCloseDevice1(HANDLE m_hDevice)
bool __stdcall VbAuxChannelConnect1(HANDLE m_hDevice,const char *IPAddressSerial, VBAUXTYPE SerialPort, int Priority, bool Persistant, VBAUXCHANCALLBACK myCallback)
/CODE]
Thsnks for the response.
I will try that but there is something I iver looked mentioning that I think will impact on this.
I am creating a DLL that is returning the value to VB,
how do I get the charr** to output from the DLL?
May other public Functins all look like this
[code]ccp[
int __stdcall VbCleanup1()
bool __stdcall VbCloseDevice1(HANDLE m_hDevice)
bool __stdcall VbAuxChannelConnect1(HANDLE m_hDevice,const char *IPAddressSerial, VBAUXTYPE SerialPort, int Priority, bool Persistant, VBAUXCHANCALLBACK myCallback)
/CODE]
I never created a DLL for visual basic in C, but as far as I know visual basic uses BSTR strings rather than chars.
Forgive my ignorence but what does that mean?
Forgive my ignorence but what does that mean?
It usually means your dll is a COM object that supports IDispatch and you address is returned in a VARIANT. If you support IDispatch, then your DLL object will appear in the Visual Basci Object Browser.
The BSTR that Cucumber mentioned is a Basic STRing. That is, it is a char array where the length of the array is at the beginning and it may contain any number of C-style strings separated by a \0. At the very end, the BSTR terminator is a \0\0.
You will need to read up on this.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Steve |
last post by:
Hello (and a happy new year)
I'm quite new to C++ and have to programm something for school and can't
get my head around
a couple of things, but at the moment this one is the most important for...
|
by: Fernando |
last post by:
Hello,
I want call, from main program, to a function (with void arguments), what it
run the function program and return the data of type char. I have make a
example of code, by it don´t run, I...
|
by: Nascimento |
last post by:
Hello,
How to I do to return a string as a result of a function.
I wrote the following function:
char prt_tralha(int num)
{
int i;
char tralha;
|
by: priya |
last post by:
Hi all,
I am new to this group.I am working in c language.I have dount
in pointer? how to retun array of pointer in function?
example
main()
|
by: cdg |
last post by:
Could anyone tell me why a function return with this program is not
returning to "main". The program will compile and should be
self-explanatory. And any suggestions for improvements would be...
| |
by: Aff |
last post by:
Brothers ,
i am facing a problem which is as follow:
class poly
{
private:
char name;
int capacity;
public:
poly(char , int );
|
by: Pedro Pinto |
last post by:
Hi there once more........
Instead of showing all the code my problem is simple.
I've tried to create this function:
char temp(char *string){
alterString(string);
return string;
|
by: nick048 |
last post by:
Hi to all
I have in my program 2 arrays DIM 2:
firstArray and secondArray
fisrtArray is for example 'ABCD' plus terminator '\0'.
I need to create a function in order to perform this in my...
|
by: vignesh4u |
last post by:
I am trying to implement the Split function in C ie.
if i have a string: char* S="This is a test";
and if i try to split based on space ' ' it should return an array of
strings like:
...
|
by: MN |
last post by:
I have 2 questions:
1- Why isn't possible to declare a static char array
inside function ?
the compiler gives this error: storage size of ‘array’ isn’t
constant.
2- Why isn't possible to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
|
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...
| |
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |