-1

I actually need my driver to read (line by line) some programs that are going to be blacklisted.

_T("bannedfile.exe") is where I actually need to put the blacklisted program.

How can I make _tcscmp read a text file, line by line?

(It makes a comparison between the host program that loads the driver, and the blacklisted one)

BOOL ProcessBlackList() {
    TCHAR modulename[MAX_PATH];
    GetModuleFileName(NULL, modulename, MAX_PATH);
    PathStripPath(modulename);
    if (_tcscmp(modulename, _T("bannedfile.exe")) != 1) {
        return 0;
    }
    else {
        return 0x2; 
    }   
}
Paul R
  • 208,748
  • 37
  • 389
  • 560
Keppy
  • 3
  • 4
  • 2
    So you just want to read a list of filenames from a file? It's not clear what this question has to do with blacklisting, specifically. – MrEricSir Aug 16 '15 at 21:25
  • Yea, exactly what you said. Sorry for my bad explanation. It reads the blacklisted programs from a list of filenames, and if one of them is the one that loaded my driver, it'll automatically say that there are 0 MIDI ports available, forcing WinMM to unload it. – Keppy Aug 16 '15 at 21:32

1 Answers1

0

Can't be done that way.

You should be able to use use getline to read the file line by line and then pass the lines to _tcscmp. Should work something like this:

wchar_t const name[] = L"bannedfile.exe";
std::wifstream file(name);

std::wstring line;
while (std::getline(file, line)
{
    if (_tcscmp(modulename, line.c_str()) == 0) {
        return TRUE; //module is in list
    }
}
return FALSE; // module is not in list

Lacking a copy of VS to test it at the moment.

If you run into unicode parsing problems because the file's encoding isn't quite what the defaults expect, give this a read: What is std::wifstream::getline doing to my wchar_t array? It's treated like a byte array after getline returns

Community
  • 1
  • 1
user4581301
  • 33,082
  • 7
  • 33
  • 54
  • It doesn't seem to be reading the file at all. My driver is still listed in the available MIDI devices, while it shouldn't be there. (If a blacklisted process tries to load the driver, it'll return 0 to MODM_GETNUMDEVS, forcing the WinMM to unload it) The function is always giving return -2 for some reasons. – Keppy Aug 17 '15 at 02:40
  • @Keppy That would be because I'm dumb. All of the strcmp functions return <0 if string 1 is less than string 2, >0 if string 1 is greater than string 2 and 0 if string 1 equals string two. II'll have the example updated in a moment. Dumb, dumb, dumb. I've known this for 20 years. Dumb. – user4581301 Aug 17 '15 at 05:48
  • Yea I noticed that error with a friend, and it now works just fine! Thank you so much! – Keppy Aug 17 '15 at 06:18