LabWindows/CVI

annulla
Visualizzazione dei risultati per 
Cerca invece 
Intendevi dire: 

CVI 2013 generate invalid code

Risolto!
Vai alla soluzione

Hi,

CVI 2013 generate invalid code for function pointer.

For example, this code works fine in CVI 2012, but not in CVI 2013. Any idea?

#include <windows.h>
#include <stdio.h>

struct FunctionType
{
	const char *name;
	void *func;	
};

static const struct FunctionType functions[] =
{
	{ "func", GetFullPathName },
};

typedef DWORD (WINAPI *GetPathFunc)(LPCSTR, DWORD, LPSTR, LPSTR *);

int main(int argc, char *argv[])
{
	char buf[256];
	GetPathFunc f = (GetPathFunc)functions[0].func;
	
	if (f != GetFullPathName) {
	
		puts("Invalid ptr");
		
	} else {
	
		if (f(argv[0], sizeof(buf), buf, NULL) > 0) {
		
			puts(buf);
		}
	}
	
	return (0);
}

 

0 Kudos
Messaggio 1 di 3
4.211Visualizzazioni
Soluzione
Accettato da autore argomento hglee

Hello hglee,

 

Your code looks fine. I have filed bug report #423480 to track the issue.

 

Our new compiler is importing GetFullPathName inconsistently. In the main function, it refers directly to the implementation in kernel32.dll. In the static variable, it refers to the "import pointer" for the function (pointer to the implementation). Interestingly, in CVI 2012 we refered to the "import stub" in both cases (a jump through the pointer to the implementation).

 

As a temporary workaround, you can manually undo the extra level of indirection by changing one line in your code:

 

	GetPathFunc f = *(GetPathFunc*)functions[0].func;

 

However, this is DANGEROUS because, depending on how we decide how to fix the problem, the workaround may become a bug itself in the future and it may crash your program. So please keep this in mind when you modify your code (for example, add a comment and a link to this post to remind you).

 

Thanks,

 

Peter

Messaggio 2 di 3
4.190Visualizzazioni

I'll wait for next service pack.

 

Thanks.

 

0 Kudos
Messaggio 3 di 3
4.181Visualizzazioni