views:

78

answers:

2

Hi,

I am writing a function that takes in a output target file and a couple of other arguments. I am currently having trouble with converting types between the argument passed in and using it in the fopen_s() method.

FILE* outputf;

void myfunc(FILE* fin, CString finpath,...)
{

  outputf = fopen_s(&fin, finpath, "w");
  .......
}

I've been stuck on this for a while and could use some help on this one. I am developing in Visual Studio 2008

Thanks

A: 

Maybe you just have to cast CString to LPCTSTR:

outputf = fopen_s(&fin, (LPCTSTR)finpath, "w");
Jack
I tried that and it didn't fix anything :(
werty0u
A: 

Looks like I found my answer. Turns out that fopen_S doesn't allow shared access to the FILE* specified for opening. I had to use _fsopen instead and that solced my problem!

werty0u