Help me please (fopen doesn't work)

Место, где разработчики плагинов могут поделиться своим опытом.
Post Reply
sad101010
Posts: 2
Joined: Mon 27 Oct, 2025 09:22

Help me please (fopen doesn't work)

Post by sad101010 »

Hello there. This is HelloWorld sample from FAR's github repo. I've compiled it and it worked, until I tried to add fopen into ProcessEditorInputW.
Why does this happen?

Code: Select all

#include "plugin.hpp"
#include "HelloWorldLng.hpp"
#include "version.hpp"
#include <initguid.h>
#include "guid.hpp"
#include "HelloWorld.hpp"
#include <stdio.h>

static struct PluginStartupInfo Info;

void WINAPI GetGlobalInfoW(struct GlobalInfo *GInfo)
{
	GInfo->StructSize=sizeof(struct GlobalInfo);
	GInfo->MinFarVersion=FARMANAGERVERSION;
	GInfo->Version=PLUGIN_VERSION;
	GInfo->Guid=MainGuid;
	GInfo->Title=PLUGIN_NAME;
	GInfo->Description=PLUGIN_DESC;
	GInfo->Author=PLUGIN_AUTHOR;
}

/*
 Функция GetMsg возвращает строку сообщения из языкового файла.
 А это надстройка над Info.GetMsg для сокращения кода :-)
*/
const wchar_t *GetMsg(int MsgId)
{
	return Info.GetMsg(&MainGuid,MsgId);
}

/*
Функция SetStartupInfoW вызывается один раз, перед всеми
другими функциями. Она передается плагину информацию,
необходимую для дальнейшей работы.
*/
void WINAPI SetStartupInfoW(const struct PluginStartupInfo *psi)
{
	Info=*psi;
}

/*
Функция GetPluginInfoW вызывается для получения информации о плагине
*/
void WINAPI GetPluginInfoW(struct PluginInfo *PInfo)
{
	PInfo->StructSize=sizeof(*PInfo);
	PInfo->Flags=PF_EDITOR;
	static const wchar_t *PluginMenuStrings[1];
	PluginMenuStrings[0]=GetMsg(MTitle);
	PInfo->PluginMenu.Guids=&MenuGuid;
	PInfo->PluginMenu.Strings=PluginMenuStrings;
	PInfo->PluginMenu.Count=ARRAYSIZE(PluginMenuStrings);
}

/*
  Функция OpenPluginW вызывается при создании новой копии плагина.
*/
HANDLE WINAPI OpenW(const struct OpenInfo *OInfo)
{
	const wchar_t *MsgItems[]=
	{
		GetMsg(MTitle),
		GetMsg(MMessage1),
		GetMsg(MMessage2),
		GetMsg(MMessage3),
		GetMsg(MMessage4),
		L"\x01",                      /* separator line */
		GetMsg(MButton),
	};

Info.Message(&MainGuid,           /* GUID */
	NULL,
	FMSG_WARNING|FMSG_LEFTALIGN,  /* Flags */
	L"Contents",                  /* HelpTopic */
	MsgItems,                     /* Items */
	ARRAYSIZE(MsgItems),          /* ItemsNumber */
	1);                           /* ButtonsNumber */

return NULL;
}
//////////// my edits ////////////////
intptr_t WINAPI ProcessEditorInputW(const struct ProcessEditorInputInfo *Info) {
	FILE* f = fopen("C:\\Users\\d\\Desktop\\far.txt", "w");
	if(f == NULL)
		return 0;
	fprintf(f, "test\n");
	fclose(f);
	return 0;
}
2useven10
Posts: 5427
Joined: Mon 07 Sep, 2009 10:40
Has thanked: 21 times
Been thanked: 349 times

Help me please (fopen doesn't work)

Post by 2useven10 »

1) make sure that you have write access to folder C:\Users\d\Desktop
2) use _wfopen() instead of fopen
Last edited by 2useven10 on Mon 27 Oct, 2025 11:37, edited 2 times in total.
sad101010
Posts: 2
Joined: Mon 27 Oct, 2025 09:22

Help me please (fopen doesn't work)

Post by sad101010 »

2useven10 wrote: Mon 27 Oct, 2025 10:44 1) make sure that you have write access to folder C:\Users\d\Desktop
2) use _wfopen() instead of fopen
1) Yes, access is fine
2) Well, my cygwin64 tells that _wfopen not found :(
Using cygwin64 with gcc to compile that.
Post Reply

Return to “Разработка плагинов”