![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
If I have a function such as this (in a Win32 project): _declspec (dllexport) char* _stdcall view() { char* output; // HOW DO I assign "THIS IS AN ARBITRARY STRING" to output return output; } The objective is that a native (unmanaged code) client [that is, I cannot use _clrcall] calling the function view in the Win32 DLL receives the string "THIS IS AN ARBITRARY STRING" |
#3
| |||
| |||
|
|
The cleanest solution is to not do it that way. Instead do what the Win32 APIs do - have the function accept a buffer pointer and a parameter that specifies the length of the buffer, you then just copy as much as will fit into the buffer area. |
#4
| |||
| |||
|
|
Dave, Thank you very much. I like your 'cleanest' solution and understand that Win32 APIs (eg GetCurrentDirectory) work that way, I need a little more help with the construction of the APIs signature. If the API is GetNewestFile, which takes one argument, a path and now will take a buffer and another argument that is the length of the bufffer. What would be the fignature of GetNewestFile? I can think of this: _declspec (dllexport) char* _stdcall GetNewestFile(char *path,char* buf,int buflen) |
#5
| |||
| |||
|
|
Dave, Thank you very much. I like your 'cleanest' solution and understand that Win32 APIs (eg GetCurrentDirectory) work that way, I need a little more help with the construction of the APIs signature. If the API is GetNewestFile, which takes one argument, a path and now will take a buffer and another argument that is the length of the bufffer. What would be the fignature of GetNewestFile? I can think of this: _declspec (dllexport) char* _stdcall GetNewestFile(char *path,char* buf,int buflen) Is this correct? [I have no experience of writing Win32 APIs]. Thanks for your help. "David Lowndes" wrote: The cleanest solution is to not do it that way. Instead do what the Win32 APIs do - have the function accept a buffer pointer and a parameter that specifies the length of the buffer, you then just copy as much as will fit into the buffer area. |
#6
| |||
| |||
|
|
Dave, Thank you very much. I like your 'cleanest' solution and understand that Win32 APIs (eg GetCurrentDirectory) work that way, I need a little more help with the construction of the APIs signature. If the API is GetNewestFile, which takes one argument, a path and now will take a buffer and another argument that is the length of the bufffer. What would be the fignature of GetNewestFile? I can think of this: _declspec (dllexport) char* _stdcall GetNewestFile(char *path,char* buf,int buflen) I'd do it like this (skipping the export & calling convention stuff for clarity): BOOL GetNewestFile( LPWSTR Path, UINT PathBufferLength ); It'd return TRUE (non-zero) if it succeeds, FALSE if something's amiss. Note that it'd be wide-character (Unicode) rather than ANSI - since all supported Windows OS's are now natively Unicode - so ANSI doesn't make much sense these days for file/path names. A typical use would be like this: WCHAR szPath[_MAX_PATH]; if ( GetNewestFile( szPath, _countof( szPath ) ) ) { // szPath now contains whatever it should do... Dave . |
#7
| |||
| |||
|
|
I figured out the signature: I need to use the [out] attribute for the buf and buflen arguments. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |