- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have been trying to use the Windows light-weight utility API StrStr to parse
the Environment strings accessed by GetEnvironmentStrings.
I have hacked it by reading a character at a time, but using StrStr would be a more
elegant way if only I could get it to work.
The code fragment below contains one of my (many) attempts, but they all end with:
GetEnvStr.obj : error LNK2001: unresolved external symbol _StrStr@8
Debug/GetEnvStr.exe : fatal error LNK1120: 1 unresolved externals
It seems to make no difference whether I add shlwapi.lib in Projects Settings Link,
and presumably I have got the settings in the interface wrong. Can anyone point
out my errors please? Or cannot these APIs be accessed?
Baffled again
Alan
the Environment strings accessed by GetEnvironmentStrings.
I have hacked it by reading a character at a time, but using StrStr would be a more
elegant way if only I could get it to work.
The code fragment below contains one of my (many) attempts, but they all end with:
GetEnvStr.obj : error LNK2001: unresolved external symbol _StrStr@8
Debug/GetEnvStr.exe : fatal error LNK1120: 1 unresolved externals
It seems to make no difference whether I add shlwapi.lib in Projects Settings Link,
and presumably I have got the settings in the interface wrong. Can anyone point
out my errors please? Or cannot these APIs be accessed?
Baffled again
Alan
program GetEnvStr ! Program gets Environmental strings (see Simon Windows NT WIN32 API ! Superbible pp 1109-1110) use kernel32, only : FreeEnvironmentStrings, GetEnvironmentStrings use dfwinty, only : LPSTR implicit none integer*4 lpTemp, lpValue ! interface function StrStr(lpFirst, lpSrch) integer(LPSTR) :: StrStr ! Long Pointer to string !DEC$ ATTRIBUTES DEFAULT, STDCALL, DECORATE, ALIAS:'StrStr' :: StrStr !DEC$ ATTRIBUTES REFERENCE, IGNORE_LOC, ALLOW_NULL :: lpFirst integer(LPSTR) lpFirst ! LPCTSTR lpFirst !DEC$ ATTRIBUTES VALUE, IGNORE_LOC, ALLOW_NULL :: lpSrch character(*) lpSrch ! LPCTSTR lpSrch end function end interface ! lpTemp = GetEnvironmentStrings() lpValue = StrStr(lpTemp+1, '=') ! end program GetEnvStr
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'd question your need to use StrStr in the first place, good ole INDEX should be able to take care of you if you set up your variables right.
Anyhow with regard to your interface, you want the routine alias to be StrStrA unless you are using wide characters, lpFirst should not need special attributes the way you are trying to use it, rather it should be passed by value, and lpSrch is the one that should have the reference attribute.
James
Anyhow with regard to your interface, you want the routine alias to be StrStrA unless you are using wide characters, lpFirst should not need special attributes the way you are trying to use it, rather it should be passed by value, and lpSrch is the one that should have the reference attribute.
James
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
James,
Many thanks for your speedy and accurate diagnosis. I had managed to convince myself that the REFERENCE and VALUE Attributes should have been the other way round, as well as not previously understanding the necessity for the terminal A on StrStr in the Alias. Perhaps I should change my brand of whisky.
I agree that INDEX does just as well, and I used it in my other method of hacking the problem. But I was intrigued by these light-weight APIs and will probably set up a library interface to facilitate using them whenever I come across them in C++ programs that I need to translate.
If Steve is reading this, may I suggest that such a library interface be included in a future version of CVF?
Happy Christmas!
Alan
Many thanks for your speedy and accurate diagnosis. I had managed to convince myself that the REFERENCE and VALUE Attributes should have been the other way round, as well as not previously understanding the necessity for the terminal A on StrStr in the Alias. Perhaps I should change my brand of whisky.
I agree that INDEX does just as well, and I used it in my other method of hacking the problem. But I was intrigued by these light-weight APIs and will probably set up a library interface to facilitate using them whenever I come across them in C++ programs that I need to translate.
If Steve is reading this, may I suggest that such a library interface be included in a future version of CVF?
Happy Christmas!
Alan

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page