Bonjour,

J'ai un problem de cast entre BSTR et const char*.

Comme vous pouvez le constater dans les fonctions ci dessous ,que IsKnownFormat prend en parametre un BSTR argument(argument muet) alors que le paremetre envoye par la fonction appelante c'est un const char*.

je n'ai pas le droit de changer le prototype des fonctions

CreatePictureFromAny // qui doit tjrs recevoir un const char*
ImportDllIsKnownFormat // qui doit recevoir un BSTR
IsKnownFormat // qui doit recevoir un BSTR




Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
PictSelection* 
Imported::CreatePictureFromAny (const char* path, State* state,const char *t ,
							   const double rapport, const char* opt_str) 
{
    const char *typ;
    if (t) 
	{
		typ=t;
    }
	else 
	{
		typ=strrchr(path,'.');
    }
    if (!(typ==nil || *typ != '.'))
	{
		if (ViewPort::IsAViewPortFile(path))
		{
			return ViewPort::InsertFile(path);
		}
		else if (!_stricmp (typ, ".bmp"))
		{
			return CreatePictureFromBMP(path, state);
		}
		else if (!_stricmp (typ, ".tif") || !_stricmp (typ, ".tiff"))
		{
			return CreatePictureFromTIFF(path, state->GetGraphicGS(), true);
		}
		else if (!_stricmp (typ, ".pv"))
		{
			/*********/
			/* prima */
			/*********/
			PictSelection* pict = CreatePictureFromImportComponent(path, state);// First try import component
			if (pict)
				return pict;
			else
				return CreatePictureFromPV(path, state);// Then try rasterization
		}
		else if (!_stricmp (typ, ".ps") || !_stricmp (typ, ".eps") ||
				!_stricmp (typ, ".ai") ||  !_stricmp (typ, ".pdf") || !_stricmp (typ, ".psi"))
		{
			return CreatePictureFromPostScript(path, state);
		}
		else if (!_stricmp (typ, ".mdl")) 
		{
			return CreatePictureFromModaris(path, state, nil );
		}
//		else if (!_stricmp (typ, ".pst"))
//		{
//			return CreatePictureFromImportComponent(path, state);
//		}
                         // C'est la ou se pose le probleme
	            else if (ImportDllIsKnownFormat((BSTR) path) == S_OK) 
		{
			DesignImport* pImport = new DesignImport(state);
			char* opt_str="-p-r-d-f-t";
			double rapport = 0.0;
			int seam_line=1;
			int special_text=1;
			int sptxt_fixed_size=1;
			if (ImportDllReadFile((BSTR)path, pImport, 0.0,false,rapport, opt_str,special_text,sptxt_fixed_size,seam_line) != S_OK)
			{
				delete pImport;
				return NULL;
			}
			else
			{
				PictSelection* slpict = pImport->GetPictSelection();
				// cleaning useless object
				pImport->Clean();
				slpict->Deplier();
				delete pImport;
				return slpict;
			}
		}
		else
			return CreatePictureFromImportComponent(path, state);
	}
    return nil;
}
et voici les fonction ImportDllIsKnownFormat && IsKnownFormat :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
HRESULT ImportDllIsKnownFormat(BSTR filename)
{
	CLectraReader reader;
	return reader.IsKnownFormat(filename);
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
 
HRESULT STDMETHODCALLTYPE CLectraReader::IsKnownFormat(/* [in] */ BSTR filename)
{
	wchar_t* extension = wcsrchr(filename, L'.');
	if ( ! extension)
		return S_FALSE;
	if ( ! wcsicmp(extension, L".dxf"))
		return S_OK;
	else
		return S_FALSE;
 
}
J'ai essayer de faire un cast comme suit :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
ImportDllIsKnownFormat((BSTR) path)
Mais ca ne marche pas, ca fait pas ce que je voulais !!


quelqu'un aura une idée comment procede pour faire le cast sans que je cree un objet BSTR avec le string path ? si non qu'est ce que vous me suggerez ?

Merci en avance